9951 explained code solutions for 126 technologies

php-symfonyHow to send emails in Symfony with PHP?

Sending emails in Symfony with PHP is a simple process.

First, create a Swift_Message object with the necessary parameters:

$message = (new Swift_Message('Subject'))
    ->setFrom(['[email protected]' => 'John Doe'])
    ->setTo(['[email protected]', '[email protected]' => 'A name'])
    ->setBody('Here is the message itself')

Then, use the mailer service to send the message:


The Swift_Message object takes the following parameters:

  • Subject: The subject of the email
  • From: An array of sender's email address and name
  • To: An array of receiver's email address and name
  • Body: The body of the email

Helpful links

Edit this code on GitHub