zend-mail
zend-mail copied to clipboard
Not overriding from mail header
When using smtp transport api for sending mail, 'from' header doesn't change by using ->setFrom() or ->setSender() and 'from' header always remains the same email address used for smtp user for authentication. In following example, from email address remains same as '[email protected]' instead of '[email protected]'.
Note: Sender name gets changed with 'Some Sender' (but not the email)
$transport = new SmtpTransport();
$options = new SmtpOptions();
$options->setHost('smtp.gmail.com')
->setConnectionClass('login')
->setName('smtp.gmail.com')
->setConnectionConfig(array(
'username' =>'[email protected]',
'password' => 'mypassword',
'ssl' => 'tls'
));
$transport->setOptions($options);
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('[email protected]', 'Some Sender');
$mail->addTo('[email protected]', 'Some Recipient');
$mail->setSubject('TestSubject');
$mail->send($transport);
This repository has been closed and moved to laminas/laminas-mail; a new issue has been opened at https://github.com/laminas/laminas-mail/issues/46.