cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PHP mail not sending after fixing mx records

Hi all,

I'm sorry, I know this issue has come up many many times, and I'm sure it will come up many more times after this, but I'm having trouble using the PHP mail() function. The simple script worked on an old host with no issue other than latency however I can't get it to work here on GoDaddy. I've read over and over that I need to change my MX Records which I have now done. The MX Records point to the correct destination (I hope) and uses the correct subdomain. I run the script and nothing happens.

 

Anyone got any ideas on how I may be able to fix this before I ring GoDaddy's Help Centre?

My 'simple mail script' is as follows:

 

 (For testing purposes only. User enters email address and the sending.php script uses the input as a target address)

<html>
<head></head>
<body>

<form action="sending.php" method="post" name="sendMail">

  <input type="email" name="email">
  
  <input type="submit">

</form>

</body>
</html>

 

(sending.php script)

<?php

$to = $_POST['email'];

$subject = 'the subject';
$message = 'hello';


mail($to, $subject, $message);
?>

 

Thank you in advanced for any support and assistance. 🙂

1 REPLY 1

Hi @srcurtis,


I had to do some digging to get everything working properly myself ( no issues with sending though did have issues with mail going to spam ). Though you are missing some important headers, as well as a "from" email address and some other necessary code to prevent the email from going to spam with gmail and such.

 

Here is some general info on setting up php mail with godaddy :

 

https://www.godaddy.com/help/using-our-php-form-mailers-on-web-and-classic-hosting-8376#webformmaile...

 

Try this :

 

<?php

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

$headers .= 'From:DisplayName<youremail@domain.com>' . "\r\n";

$headers .= 'Reply-To:youremail@domain.com' . "\r\n";
$headers .= 'Return-Path:youremail@domain.com';

$to = $_POST['email'];

$subject = 'the subject';
$message = 'hello';

mail($to,$subject,$message,$headers,"-f youremail@domain.com");

?>

 Edit the "youremail@domain.com" to a physical email address set up on the same domain you are sending from. Set this email up in the Workspace section of GoDaddy ( assuming that's what you are using ), this will help you email getting verified. As for your MX record, I am not sure what you did, though you may also need to add a new line to your DNS settings to also prevent the email from going to spam. This isn't necessary for actually sending email.

More on that here :


https://www.godaddy.com/community/Managing-Email/Gmail-isn-t-verifying-my-email-address-Workspace-em...