• GoDaddy Community
  • Managed WordPress Hosting
  • Managed WordPress Hosting

    Showing results for 
    Show  only  | Search instead for 
    Did you mean: 
    Go to solution

    PHP mail function not working

    I am having trouble getting support to do any useful testing or explanation. 

    My issue is I am not receiving emails when sending from the web server using PHP mail() function.

    Support ran a test using a 3,000 line script with all sorts of config for which I received the email and they say that is a sufficient test to show that email works.

    This is ridiculous since you should just be able to issue a short php mail() command and have email sent. I do not receive anything using the below script.

    I believe this to be a server config issue but support will not even look at it.

    $to = 'myemail@gmail.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: myemail@mydomain.com' . "\r\n" .
    'Reply-To: myemail@mydomain.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);


    What can I do to check. Is there anything I can do in the php.ini file to set this up?

    Is it a server config error?

    4 REPLIES 4
    Super User II
    Super User II

    Re: PHP mail function not working

    Hello think what might be needed is to add the To field to the headers.


    $headers .= "To: $email\r\n";

    Also, on many servers, the From field has to contain an email address that actually exists in the account.  I think this depends on what kind of hosting plan you have but it couldn't hurt to define one of your free accounts as noreply@whatever.com and set it's mailbox size to 1MB.


    Zulfiqar Anees | Founder/CEO at FastTech Media, TechMag, and ZulWeb | GoDaddy Pro.

    Re: PHP mail function not working

    Php's mail() function doesn't use SMTP. As far as I'm aware the server should auto use the relay server if you use mail()?
    Rockstar I Rockstar I
    Rockstar I

    Re: PHP mail function not working

    Hi @qwertyjjj ,


    I've had similar problems, and they are not always easy to solve.  One thing I have done is contact support and have them walk me through getting the fully qualified name of the relay server and using it in the config.  This is not a perfect solution, but just a work around.  Depending on the why the auto config for the relay is not working, this may or may not work.


    Also, email servers can be quite particular on what is ACTUALLY sent.  Make sure that all of your mail server records are correct.  You can check some of this with the toolbox at https://mxtoolbox.com/.


    Hope this helps,


    Not Just Pretty Sites, Pretty Doggone Smart Sites

    Re: PHP mail function not working

    support were no use at all. what I had to do was install a wordpress plugin to force all mail to be sent by smtp. now it works.