Question

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
Was it helpful?

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";

OTHER TIPS

I came to this question looking for something different but with similar words, so here's how to do what I was looking for:

In the from header, put the address in angle brackets, and the "sender name" outside of it.

from: Don Draper <don.draper@website.com>\n

I wanted the inbox to say Don Draper instead of don.draper and that's how to do it.

You can also try adding the From address to the mail's 'envelope' by utilizing the fifth parameter in PHP's mail() function:

mail($to_mail, $subject, $message, $headers, "-f$from_email");

Reference here.

Reference regarding mail headers and envelopes here

Note that some server setups may disallow this or throw a warning, depending on their configuration and/or the configuration of the mail transfer agent. This answer talks about updating sendmail's 'trusted users' with regards to this.

Add this line before header line

$headers .= "From: Your Name <sitename@hostname.com> \r\n";

So the code will be

$headers = "";
$headers .= "From: WIFI Metropolis <sitename@hostname.com> \r\n";
$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);

Simply add the From header. Something like this.

$headers .= "From: website@mydomainname.com";

Try to add From: to the header

$headers = "" .
           "Reply-To:" . $from . "\r\n" .
           "From:" . $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";  

Some MTA can change/ignore this definition to avoid SPAM, and override with user of SMTP configured in PHP.ini

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top