-1

I created a website to send a letter to Santa (actually sends it to your parents) and it works perfectly fine on all of my email accounts. I have received feedback that Gmail is ignoring the emails, so I tested it and sure enough they never show up. I'm guessing it has to do with my email headers? I'm not experienced enough at PHP to know how to change the from address to not be from the recipient.

$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);

Those are my headers. The full PHP can be found at https://pastebin.com/SLtZ6GxN and the html can be found on the website at dearsanta.fun

Thanks for reading.

I tried changing the headers to:

$headers = 'From: santa@dearsanta.fun' . "\r\n".
'Reply-To: santa@dearsanta.fun' "\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);

and now on submit I am redirected to a white page and the address it to the php form. So the answer given in the other thread seems to have broken my script.

Kevin
  • 83
  • 1
  • 9
  • 1
    "I'm not experienced enough at PHP to know how to change the from address to not be from the recipient." -- Just change to `$headers ="From:noreply@mydomain.com\r\n"` where mydomain.com = the domain sending the email. – Sablefoste Nov 22 '17 at 14:37
  • You didn't research this enough. – Funk Forty Niner Nov 22 '17 at 14:39
  • @Fred-ii- Sorry but I've been researching this for 10 hours, I just have no idea what I am doing, lol. I'm just trying to make something for my nieces and nephews but I may be in over my head when it comes to PHP, I am a lowly front end developer. – Kevin Nov 22 '17 at 15:14
  • I think you may not have used the right phrase/keywords. Using: "why is gmail blocking my emails php" brought back many results. I only used two duplicated questions here, I could have added more. – Funk Forty Niner Nov 22 '17 at 15:17
  • @Sablefoste That broke the script.. – Kevin Nov 22 '17 at 15:17
  • @Fred-ii- I understand that there are other questions similar or maybe even the same but all of the answers given in them break my script so are not my solution – Kevin Nov 22 '17 at 15:18
  • *"all of the answers given in them break my script"* - Check your syntax then. That would not be relevant to the original question and is out of the scope of the original post. – Funk Forty Niner Nov 22 '17 at 15:19
  • @Fred-ii- Thank you, using the answer from ceejayoz I was able to fix it by looking up the proper syntax on w3schools – Kevin Nov 22 '17 at 15:33

1 Answers1

1

It looks like $email_from comes from the user's input. Won't work - Gmail will correctly detect (via SPF records) that your server isn't a valid sender for Gmail addresses. You need to send with a From address that's under your control, and rely on the Reply-To (which can contain any email) to direct replies to the correct recipient.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • You should also consider a proper mail class like SwiftMailer. Your raw mail() code is likely vulnerable to mail header injection. – ceejayoz Nov 22 '17 at 14:36
  • That was my hunch but I'm just not sure how to do that. I am fine with HTML/CSS and other front end technologies but I'm a total PHP n00b. – Kevin Nov 22 '17 at 14:37
  • Do what? `From: noreply@dearsanta.fun`. – ceejayoz Nov 22 '17 at 14:41
  • please check my ammended question, I put those changes in and seems to have broken the script. – Kevin Nov 22 '17 at 14:55
  • 1. Check your logs. 2. Why did you change the `Reply-To`? You should've left that part alone. – ceejayoz Nov 22 '17 at 15:00
  • ok I changed the whole thing to how it was and just edited to From line to: $headers = 'From: santa@dearsanta.fun'.$email_from."\r\n". The form worked but still didn't make it to gmail, is my syntax even correct there? – Kevin Nov 22 '17 at 15:10
  • I solved it by correcting the syntax according to the tutorial on w3schools. Thanks for the help – Kevin Nov 22 '17 at 15:32