Search code examples
phpemailemail-headers

Change the sender name php mail instead of sitename@hostname.com


I am trying to send email from my php :

$to = 'it@7sisters.in';
    $email_from = "info@7sisters.in";

    $full_name = 'Suraj Hazarika';
    $from_mail = $full_name.'<'.$email_from.'>';



    $subject = "testing sender name";
    $message = "";
    $message .= '
            <p><strong>This is only a test . Please do not reply.</strong><br />
    ';
    $from = $from_mail;

    $headers = "" .
               "Reply-To:" . $from . "\r\n" .
               "X-Mailer: PHP/" . phpversion();
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";        
    mail($to,$subject,$message,$headers);

I am following the tutorial PHP E-mail Form Sender Name Instead Of E-mail? but I am still getting the emails with sender name with hostname.

     From                              Date             Subject 
sisters@rsx02.justhost.com  Fri, 11:24 pm       testing sender name
sisters@rsx02.justhost.com  Fri, 11:24 pm       testing sender name

Solution

  • You only use $from in your Reply-To header. If you want it to be in the From header, you need to set it in the From header.

    Put something like this before your mail() command:

    $headers .= 'From: ' . $from . "\r\n";