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

  // Set up the Smtp connection using your google account
  $connection   = new Swift_Connection_SMTP('', 465,
  $connection->setUsername('' );
  $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);
catch (Exception $e)
  // 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);