I’m tryng to send an email with this script
$to = 'example@example.com';
$headers['To'] = $to;
$headers['From'] = '"My Name" <examlpe@example.com>';
$headers['Return-Path'] = 'examlpe@example.com';
$headers['Subject'] = 'Subject';
$auth = array('host' => MAIL_HOST, 'auth' => true, 'username' => MAIL_USER, 'password' => MAIL_PASS);
$smtp = Mail::factory('smtp', $auth);
$mail = $smtp->send($to, $headers, $message);
if (PEAR::isError($mail))
echo('<p>PEAR mail: '.$mail->getMessage().'</p>');
else
echo('<p>PEAR mail: Message successfully sent!</p>');
But I got the following message:
Failed to set sender: "My Name" <example@example.com> [SMTP: Invalid response code received from server (code: 501, response: <"My Name" <example@example.com>>: "@" or "." expected after ""My Name"")]
When I make the from field like this:
$headers['From'] = 'examlpe@example.com';
It works fine and I receive the email.
How can I send an email with the name of the sender?
Return-Path and Reply-To are not the same.
Return-Path: If you want to override the envelope sender of the email, set the Return-Path header and that value will be used instead of the value of the From: header (From PEAR website). You cannot set name for Return-Path, just an email address.
Reply-To: Makes the recipient reply to this address. You can set a name and an email address.
So replace Return-Path by Reply-To and it will work.