使用Swift Mailer发送大量电子邮件

时间:2015-04-07 05:48:46

标签: php email swiftmailer massmail

我编写了一个脚本来发送群发电子邮件,使用SwiftMailer库,我希望它能够批量邮寄我在文本框中输入的电子邮件列表,我该怎么做?

这是我的代码:

    <?php

include_once "swiftmailer/lib/swift_required.php";

$subject = 'Hello World!';
$from = array('sender@example.com' =>'Sender Name');
$to = array(
 'recipient1@example.com'  => 'Recipient1 Name',
 'recipient2@example.com' => 'Recipient2 Name'
);

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

$transport = Swift_SmtpTransport::newInstance('smtp-server.example.com', 25);
$transport->setUsername('mail@example.com');
$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 个答案:

没有答案