How to specify the name of the sender of the email?

I try when an email is sent in my Symfony2 application to name the sender

Administrator < no-reply@app.com > 

I tried in parameters.ini :

 mailer_from = {" no-reply@app.com : Administrator"} 

It seems possible to do this because in SimpleMessage.php we 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; } 

Everything I tried in parameters.ini failed. Do you have any idea what I'm doing wrong?

+4
source share
2 answers
 // Set a single From: address $message->setFrom(' your@address.tld '); // Set a From: address including a name $message->setFrom(array(' your@address.tld ' => 'Your Name')); // Set multiple From: addresses if multiple people wrote the email $message->setFrom(array( ' person1@example.org ' => 'Sender One', ' person2@example.org ' => 'Sender Two' )); 
+16
source

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

Well, you can set the name, but there is nothing to indicate that you can set it using the configuration.

A quick reset of the available configuration for SwitfMailerBundle ( php app/console config:dump-reference SwiftmailerBundle ) will return:

 Default configuration for "SwiftmailerBundle" swiftmailer: transport: smtp username: ~ password: ~ host: localhost port: false encryption: ~ auth_mode: ~ spool: type: file path: %kernel.cache_dir%/swiftmailer/spool sender_address: ~ antiflood: threshold: 99 sleep: 0 delivery_address: ~ disable_delivery: ~ logging: true 

As you can see, there is sender_address , which is passed to ImpersonatePlugin.php .

I'm not sure you can set a name, but the standard way is to use a line of this form:

"Administrator"

If this does not work, it probably means that you will work to write a real EmailManager.

SwiftMailerBundle is actually only an integration of the SwiftMailer library, which is a library, not a "manager."

+3
source

All Articles