Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put a name on the email sender?

I'm trying to, when an email is sent within my Symfony2 application, to name the sender

Administrator <[email protected]>

I've tried in the parameters.ini :

mailer_from      = {"[email protected] : Administrator"}

It seems possible to do so because in SimpleMessage.php we do have :

  /**
   * Set the sender of this message.
   * This does not override the From field, but it has a higher significance.
   * @param string $sender
   * @param string $name optional
   * @return Swift_Mime_SimpleMessage
   */
  public function setSender($address, $name = null)
  {
    if (!is_array($address) && isset($name))
    {
      $address = array($address => $name);
    }

    if (!$this->_setHeaderFieldModel('Sender', (array) $address))
    {
      $this->getHeaders()->addMailboxHeader('Sender', (array) $address);
    }
    return $this;
  }

All the things I tried in the parameters.ini failed. Do you have any idea of what i'm doing wrong please ?

like image 959
sf_tristanb Avatar asked Jun 21 '12 08:06

sf_tristanb


People also ask

How do you add a name to an email address?

Add a contact from an email message Open the message so that the person's name is shown in one of these lines: From:, To:, Cc:, or Bcc:. Right-click the appropriate name, choose Add to Outlook Contacts. In the window that opens, fill in the details you want to save.

What is a display name on email?

The display name is the name that appears on your outgoing emails. This is the name recipients will see when you email them.


1 Answers

// Set a single From: address
$message->setFrom('[email protected]');

// Set a From: address including a name
$message->setFrom(array('[email protected]' => 'Your Name'));

// Set multiple From: addresses if multiple people wrote the email
$message->setFrom(array(
  '[email protected]' => 'Sender One',
  '[email protected]' => 'Sender Two'
));
like image 171
dmnptr Avatar answered Nov 23 '22 22:11

dmnptr