Creating a Mailing list with swift Mailer and Symfony1.0

The Php mailer of Symfony 1.0 doesn’t handle important mailing list. No buffer, no Smtp server. The best is to use Swift mailer with a batch script processing in background…

Here is how to send an HTML email with the Swift Library with symfony 1.0:

Copy the autoload.yml in: myapps/config

try
{
  // Set up the Smtp connection using your google account
  $connection   = new Swift_Connection_SMTP('smtp.gmail.com', 465,
                                  Swift_Connection_SMTP::ENC_SSL);
  $connection->setUsername('h.le.turdu@gmail.com' );
  $connection->setPassword('xxx' );
  // Create the mailer and message objects
  $mailer = new Swift(new Swift_Connection_NativeMail());
  $message = new Swift_Message
  ('Mail\'s subject', $mailBody, 'text/html');

  // Send
  $mailer->send($message, $mailTo, $mailFrom);
  $mailer->disconnect();
}
catch (Exception $e)
{
  $mailer->disconnect();
  // handle errors here
}

and in a batch file

$swift = new Swift(new Swift_Connection_SMTP(smtp_server_address));
$recipients = new Swift_RecipientList();
$message = new Swift_Message($email_subject, $email_body);
foreach ($addresses as $address) $recipients->addTo($address);
$swiftbatchSend($message, $recipients, $from_email_address);