0

Hi I am using the the mail function in php to send emails but the emails in the inbox of the receiver show the name as "unknown sender" in gmail and going in spam in yahoo, here is the code for the function.

function send_email1($from, $fromaddress, $to, $sub, $mes)
{
  $headers = "MIME-Version: 1.0\r\n";  
  $headers .= "Content-type: text/plain; charset=utf-8\r\n";  
  $headers .= "To: ".$to." <".$to.">\r\n";  
  $headers .= "From: ".$from." <".$from.">\r\n";  
  $headers .= "Reply-To: ".$from." <".$from.">\r\n";  
  $headers .= "Return-Path: ".$from." <".$from.">\r\n";  

   mail($to, $sub, $mes, $headers);   
   return mail($to, $sub, $mes, $headers); ;
}
safeer008
  • 323
  • 4
  • 8
  • Depends on your server configuration and what you used in `$headers`. Consider using PHPMailer/SwiftMailer with your mail providers account. – mario Jan 04 '14 at 06:27
  • possible duplicate of [sending email via php mail function goes to spam](http://stackoverflow.com/questions/18229279/sending-email-via-php-mail-function-goes-to-spam) – mario Jan 04 '14 at 06:28

1 Answers1

1

I have solved the problem. The code has now become as under:

function send_email1($from, $fromaddress, $to, $sub, $mes)
{
  $headers = "MIME-Version: 1.0\r\n";  
  $headers .= "Content-type: text/plain; charset=utf-8\r\n";  
  $headers .= "To: ".$to." <".$to.">\r\n";  
  $headers .= "From: ".$from." <".$from.">\r\n";  
  $headers .= "Reply-To: ".$from." <".$from.">\r\n";  
  $headers .= "Return-Path: ".$from." <".$from.">\r\n";  
  $headers .= "\r\n";

   mail($to, $sub, $mes, $headers);   
   return mail($to, $sub, $mes, $headers); ;
}

I have just added the line

$headers .= "\r\n";

and the email is not longer without the sender's name.

safeer008
  • 323
  • 4
  • 8