0

I have a form on my GoDaddy website that uses the PHP mail() function to send an email with the completed form to a Gmail account and it's worked just fine for several years. I recently upgraded from PHP 5.2 to PHP 5.6 and then to PHP 7 and now the form is broken in a strange way. It seems to work unless the user completes the From: field with a Yahoo email address.

To help explain, here is a little script I've been using to troubleshoot:

<?php

   $to = 'flyfishing@gmail.com'; 
   $subject = 'Test mail';
   $message = 'Hello! This is a simple test email message.';
   $from = 'email@email.com';
   $headers = 'From:' . $from;
   mail($to,$subject,$message,$headers);
   echo 'Mail Sent.';
   ?>

Notice that flyfishing@gmail.com is where I need the completed form to go (it's my fly fishing club email account) and email@email.com is the email address of the person who completed the form. The script seems to work just fine unless email@email.com is a Yahoo email account. In that case, there are no error messages but the form just never shows up at Gmail. Lost in cyberspace.

I don't pretend to understand PHP very well, but I've searched for a solution for a couple of days without success. Any suggestions? I would prefer to just make the mail function work, but I understand there are alternative ways to send email from a form on GoDaddy. Any help would be greatly appreciated.

Many thanks, Dave

  • 1
    Yahoo likely has a SPF record that encourages Gmail (and others) to reject falsified `From` addresses. Setting a `From` header to an email address you don't control has long been problematic. Send from a valid `From` under your control, and set a `Reply-To: $from` instead. – ceejayoz May 13 '18 at 01:39
  • Many thanks, ceejayoz. That works and the messages arrive in the Gmail account, but they all display as coming from the valid From under my control. Reply To works, but every message is from me no matter who sent it. That will confuse the non-techie guys running the fly fishing club. – user2384436 May 13 '18 at 16:37
  • Well, it's either confusion+education or obliterated by spam filters. All of the major email providers publish SPF records. Your emails will very clearly not be coming from their systems, and will thus be widely rejected. – ceejayoz May 13 '18 at 16:39
  • Sadly, it's confusion and education. I read just one book on PHP several years ago and got myself all confused with this problem, but I think I now understand why the emails were rejected. Question: If it's working correctly, either with correct PHP coding or PHPMailer or SwiftMail or whatever, who will the emails be "From:" when they arrive in the target email account? Will they be from the user who submitted the form or will all emails come from the single email account set up in the code? I'm guessing the latter. Many thanks again. Much appreciated. Cheers. – user2384436 May 14 '18 at 15:28
  • They should come from an email address that your server is authorized (via a SPF record for the domain name) to send on behalf of. You can set a name for it by doing `From: User's Name ` so it shows up with that instead of the email address in their list. The `Reply-To` will make sure replies go to the right place. – ceejayoz May 14 '18 at 15:53
  • Great. Thank you. I think you're saying that all emails showing up in the Gmail account will be from me@example.com, but if the boys in the fly fishing club hit Reply To the response will go the user who submitted the form. Previously, the emails showing up in the Gmail account were From the user who submitted the form and that's what broke with the PHP update. Guess it's gone for good. In any case, I know how to make the Reply To work and the boys will just have to learn a new way. Many thanks for all your help. – user2384436 May 14 '18 at 16:10

0 Answers0