Sending Mass email using Swift Mailer

870 Views Asked by At

I'm coding a script to send mass email, using SwiftMailer library, i want it to mass mail a list of emails that i'll enter on a text box, how can i do that?

Here is my code:

    <?php

include_once "swiftmailer/lib/swift_required.php";

$subject = 'Hello World!';
$from = array('[email protected]' =>'Sender Name');
$to = array(
 '[email protected]'  => 'Recipient1 Name',
 '[email protected]' => 'Recipient2 Name'
);

$text = "plaintext email";
$html = "<em>just testing <strong>HTML</strong></em>";

$transport = Swift_SmtpTransport::newInstance('smtp-server.example.com', 25);
$transport->setUsername('[email protected]');
$transport->setPassword('pass123');
$swift = Swift_Mailer::newInstance($transport);

$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');

if ($recipients = $swift->send($message, $failures))
{
 echo 'Message successfully sent!';
} else {
 echo "There was an error:\n";
 print_r($failures);
}

?>
0

There are 0 best solutions below