test email via php

Discussion in 'Email' started by dlature, Apr 22, 2011.

  1. trying to figure out how to get $mail function to work for a php script I need to use.
    This page:
    https://support.Winhost.com/KB/a826/how-to-send-email-from-a-php-application.aspx

    lists a php code block that is supposed to work on Winhost.

    but I still get the error message:

    Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini


    as if I was not using the above code

    what can I do?
     
    Last edited by a moderator: Oct 14, 2015
  2. Does this work at all?

    Has this ever workedon Winhost, and if so, why can I not send mail to a recipient external to my domain? Not much use in a mail system that can't send outgoing mail.
     
    Last edited by a moderator: Oct 14, 2015
  3. Ray

    Ray

    You can't use "localhost" to send out email with your web application. Localhost symbolizes the web servers smtp service. On our web server we disabled that. When you get a Winhost account, you will get an email account. With that email account you will also get a smtp server. That is the smtp server you will use to send out email on your PHP app. As an example, mail.mydomain.com. Our smtp server requires that you pass SMTP authentication so you will need to also pass that in your PHP app.

    Try looking at this kb.

    http://support.Winhost.com/KB/a826/how-to-send-email-from-a-php-application.aspx
     
    Last edited by a moderator: Oct 14, 2015
  4. Smtp

    Ray,
    thanks for the reply. Thelink you pointed me to at the bottom of your message was indeed the same link in my original message. But I do need to update what errors I am giving. I did point to the SMTP account for my webhost account by specifying my value in $host = "mail.mydomain.org"; (using my actual domain name there) and using the administrator/postmaster mail account authentication values for the
    $username = "[email protected]";
    $password = "mypassword";
    (my actual values instead of mydomain and mypassword)

    and get this error:

    Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in E:\web\myaact\mydir\subdir\contact.php on line 115

    Your mail could not be sent this time.

    it still is trying to use localhost, even though I told it in the code (which I have placed in the head section of my php file's html code, just before the </head> tag, which is where I always put server side code that does not need to be inline in the body.

    If I try ini_set
    ini_set(SMTP,"mail.mydomain.org");
    ini_set(auth, true);
    ini_set(username,"[email protected]");
    ini_set(password,"mypassword");

    and put these lines just before the line that calls mail(), I get this error:

    Warning: mail() [function.mail]: SMTP server response: 550 <[email protected]> No such user here in E:\web\myaact\myapp\subdir\contact.php on line 115

    Your mail could not be sent this time.

    So it's not letting me send to any address other than an account on mydomain.org, which is pretty useless. I need to mail to the above address
     
  5. another quesiton might be what the
    require_once "mail.php" is doing. There is no explanation of this on the KB doc that includes that piece of code I included as instructed with my info as I indicated above
     
  6. Ray

    Ray

    Somewhere in your code it is still connecting to "localhost".

    Failed to connect to mailserver at "localhost" ..

    Check the error, it appears to be telling you what line and file it is coming from.

    Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in E:\web\myaact\mydir\subdir\contact.php on line 115

    Now this error is different and as you can see the path to the error is different.

    Warning: mail() [function.mail]: SMTP server response: 550 <[email protected]> No such user here in E:\web\myaact\myapp\subdir\contact.php on line 115

    The email address "[email protected]" is this something you are actually trying to send to?
     
  7. Nowhere do I connect to localhost. The PHP code does that by default since there is no php mail function allowed. I thought that the code in the referenced KB page would take care of this. But even when I set $host = "mail.mydomain.org it still gives the error with locahost , because my code calls mail(), which is the default php mail function which is missing from Winhost. But the provided code to allow me to send mail from my SMTP server doesn't seem to tell my app to use those SMTP settings.fist line

    I also am unsure of what the first line does
    require_once "mail.php"; in the KB article code. Where is this file and where is it supposed to be?

    I cannot get SMTP to be used unless I add
    ini_set() variables as listed in my previous post, which results in the second error message about "no such user".

    my mail function , which seems to be enabled by the ini_set variables placed right before it, is this:
    mail($recipient,$subject,$message,$headers)

    the $recipient value is the address I want it to send to, but it will not unless thatrecipient is also on my domain, which is kind of useless. How do I tell my own SMTP server that it can send outgoing mail to any $recipient?
     
    Last edited by a moderator: Oct 14, 2015
  8. Ray

    Ray

    The line require_once "mail.php" is the PEAR module that allows PHP to use another SMTP server and pass SMTP authentication. Think of it as a external method you can use to allow PHP to have an extra feature. Without it, PHP will automatically refer to "Localhost" for the smtp server.


    You really shouldn't have to use this. Once you call on "mail.php" the variables you call on base off what is in the kb will be defined to what they are suppose to be. This line however is important "$smtp = Mail::factory" because they do help pass the smtp authentication. One thing you may want to verify is the DNS records, and making sure that the A record and MX record is pointing to our servers. In some cases even after coding the php script correctly, the mail server is hosted somewhere else, and their smtp authentication maybe different to what we have. Thus the smtp authentication maybe passing wrong.
     

Share This Page