cancel
Showing results for 
Search instead for 
Did you mean: 
Go to solution

PHP mail() WILL send - this is the simple solution

I have 3 PHP forms on my website - all use the PHP send() function, and all stopped working on GoDaddy's Windows server.  We also do not host our email at GoDaddy, but do have the domain registered with GoDaddy.  The forms work perfectly on Linux hosting.  After days of research, I figured out the solution below:

 

1. You need to create a SPF Record and add it to your domain records as a txt file.  For instructions on creating the SPF file for Gmail here is the link - https://support.google.com/a/answer/33786?hl=en. However, no matter what email hosting you're using, the record you add will be very similar and will look like this -

v=spf1 include:serverdomain.com include:_spf.google.com ~all.  By adding this record, you're basically telling the server that it's safe to use your outside hosting to process email.

 

If you need help on adding it just search a little on GoDaddy's forums or wherever your domain is hosted, or contact tech support.  It's a quick and simple process.

 

2. Once you add this, it may take 24-48 hours to process - it did for me.

 

3. Back in your PHP form - Make sure that you designate a "From" email address ($From = 'info@yourdomain.com'Smiley Wink which matches the domain in the SPF Record.  So, if you added Google's mail servers in the SPF Record, make sure your "FROM" field in your form is something like "joe@gmail.com".

 

4. Finally, in your PHP form, make sure you add an ",-f .$From" to the end of your mail array so that if looks like this - 

mail($emailTo, $subjectTitle, $body, $headers, '-f'.$From);

This assures the server that your email is not spam.  

 

That's it!

 

I hope this helps some of you avoid the many painful hours I had to endure to finally figure this one out!

2 REPLIES 2
Community Manager
Community Manager
Solution

Re: PHP mail() WILL send - this is the simple solution

Fantastic @onlineinsite! Thanks so much for sharing all of this with other community members. It's so helpful. Take care!

Rachel

All mail receiving in spam folder

I am receiving all mail in my spam folder. This is my code sample: Please help me on this

 

<?php

require_once "vendor/autoload.php";

$mail = new PHPMailer;

//Enable SMTP debugging.
$mail->SMTPDebug = 3;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = "smtp.gmail.com";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = "name@gmail.com";
$mail->Password = "super_secret_password";
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "tls";
//Set TCP port to connect to
$mail->Port = 587;

$mail->From = "name@gmail.com";
$mail->FromName = "Full Name";

$mail->addAddress("name@example.com", "Recepient Name");

$mail->isHTML(true);

$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";

if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}