Can we add friendly name in email messages?
Closed this issue · 1 comments
bmellink commented
It would be great to allow adding a friendly name for the from address, in a way like this:
$m->setFrom('user@example.com', 'John Doe');
I implemented this by adding the following changes in SimpleEmailServiceMessage.php
:
public function setFrom($from, $fromname='') {
$this->from = $from;
$this->fromname = $fromname; // added statement
$this->is_clean = false;
return $this;
}
Then in SimpleEmailService.php
I made a change in the function sendEmail()
by changing the line:
$ses_request->setParameter('Source', $sesMessage->encodeRecipients($sesMessage->from));
into:
if ($sesMessage->fromname)
$ses_request->setParameter('Source', '"'.$sesMessage->fromname.'" <'.$sesMessage->from.'>');
else
$ses_request->setParameter('Source', $sesMessage->encodeRecipients($sesMessage->from));
For this to work in raw email mode the same change needs to be made to getRawMessage();
if ($this->fromname)
$raw_message .= 'From: "' . $this->fromname . '" <' . $this->from . '>' . "\n";
else
$raw_message .= 'From: ' . $this->encodeRecipients($this->from) . "\n";
Can you please add these changes to the master? (or implement the same functionality differently).
daniel-zahariev commented
Hi @bmellink ,
you can use this functionality with the following format:
$m->addTo('Recipient Name <recipient@example.com>');
$m->setFrom('Sender <user@example.com>');