PHP recipient email sending form does not receive valid email address sendr

I am trying to figure out a problem with PHP code to submit a form, im for my friend. It sends emails, but the problem is that the recipient receives a very strange email address. I attach the image to look closer.

My PHP code is:

<?php $error = false; $sent = false; if(isset($_Post['name'])) { if(empty($_Post['name']) || empty($_Post['email']) || empty($_Post['comments'])) { $error = true; } else { $to = " linardsberzins@gmail.com "; $name = trim($_Post['name']); $email = trim($_Post['email']); $comments = trim($_Post['comments']); $subject = "Contact Form"; $messages = "Name: $name \r\n Email: $email \r\n Comments: $comments"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From:" . $name . "\r\n"; $mailsent = mail($to, $subject, $messages, $headers); if($mailsent) { $sent = true; } } } ?> 

Thank you very much odd email displayed

0
source share
6 answers

It should be like Sender < HIS@EXAMPLE.COM > :

  $headers .= 'From: '.$name.' <'.$email.'>' . "\r\n"; 
+7
source

Try adding headers to email, for example from PHP mail Manual example 2

 <?php $to = ' nobody@example.com '; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com ' . "\r\n" . 'Reply-To: webmaster@example.com ' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> 

If you want this to be an email with a name, this will work

 $headers .= 'From: Birthday Reminder < birthday@example.com >' . "\r\n"; 
+2
source

Add this to your headlines.

 $headers .= "Reply-To: $replyEmail\r\n"; 
+2
source

The From: header should contain an email address as well as a name, something like

 "From:My Display Name< mydisplayname@gmail.com >\r\n" 
+2
source
 <?php $error = false; $sent = false; if(isset($_Post['name'])) { if(empty($_Post['name']) || empty($_Post['email']) || empty($_Post['comments'])) { $error = true; } else { $to = " linardsberzins@gmail.com "; $name = trim($_Post['name']); $email = trim($_Post['email']); $comments = trim($_Post['comments']); $subject = "Contact Form"; $messages = "Name: $name \r\n Email: $email \r\n Comments: $comments"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: '.$name.' < sender@example.com >' . "\r\n"; $mailsent = mail($to, $subject, $messages, $headers); if($mailsent) { $sent = true; } } } ?> 

Try it. just change the title.

 $headers .= 'From: '.$name.' < sender@example.com >' . "\r\n"; 
+2
source

Hey. This was not a mistake. If you provide SENDER EMAIL , then the senders email address will be displayed instead. Otherwise, it will take our hosting address.

0
source

All Articles