Unknown PHP Sender

Hello, I'm pretty new to PHP and don't know much at the moment. I changed the contact form and ran into some problems with mail being sent directly to the trash.

I assume this is due to the fact that (unknown sender) continues to appear in the email header. I would appreciate if someone could help me fix this. Below is the code that I have embedded on the website:

<?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $from = 'From: Wirral PT Enquiry'; $to = ' joebloggs@hotmail.com '; $subject = 'Wirral PT Enquiry'; $human = $_POST['human']; $headers = " enquiry@wirralpt.co.uk "; $body = "From: $name\n E-Mail: $email\n Message:\n $message"; if ($_POST['submit']) { if ($name != '' && $email != '') { if ($human == '2') { if (mail ($to, $subject, $body, $from)) { echo '<p>Your message has been sent!</p>'; } else { echo '<p>Something went wrong, go back and try again!</p>'; } } else if ($_POST['submit'] && $human != '4') { echo '<p> 1+1=2!! </p>'; } } else { echo '<p>You need to fill everything!!</p>'; } } ?> 
+4
source share
4 answers

$from = 'From: Wirral PT Enquiry'; must contain the email address 'from', and not just the name:

  $from = 'From: Wirral PT Enquiry < enquiry@wirralpt.co.uk >'; 

Give it a try?

+4
source

try using

 $headers = "Reply To : enquiry@wirralpt.co.uk "; 

Can work for you

also,

 $headers = "From : enquiry@wirralpt.co.uk "; 

try both of them with corresponding email ids

+1
source

Change your headers to:

 $headers = 'From: enquiry@wirralpt.co.uk ' . "\r\n" . 'Reply-To: enquiry@wirralpt.co.uk ' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); 

and your mail should look like this:

 mail ($to, $subject, $body, $headers) 
+1
source

This error can also be caused if, when using the SMTP settings for PhpMailer, $ mail-> IsSMTP (); missed

-2
source

All Articles