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 = 'email@example.com' 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 "firstname.lastname@example.org".
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.
I hope this helps some of you avoid the many painful hours I had to endure to finally figure this one out!
Solved! Go to Solution.
Fantastic @onlineinsite! Thanks so much for sharing all of this with other community members. It's so helpful. Take care!
I am receiving all mail in my spam folder. This is my code sample: Please help me on this
$mail = new PHPMailer;
//Enable SMTP debugging.
$mail->SMTPDebug = 3;
//Set PHPMailer to use SMTP.
//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 = "email@example.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 = "firstname.lastname@example.org";
$mail->FromName = "Full Name";
$mail->addAddress("email@example.com", "Recepient Name");
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
echo "Mailer Error: " . $mail->ErrorInfo;
echo "Message has been sent successfully";