4

我意识到 batchEmail 不再是新的 SwiftMailer 的一部分。所以我做了这个脚本:

<?
//
// GC PRESS EMAILER v5
//
ini_set('display_errors',1);
error_reporting(E_ALL);
require_once("config.php");
include_once("hawkmail/mail/lib/swift_required.php");
$c=mysql_connect($dbh,$dbu,$dbp);
function SendEmail(){
    // DB
    $s=mysql_query("SELECT * FROM `newgc`.`press_list`");
    // Process Color Listing Loop
    while($r=mysql_fetch_array($s)){
    // ###########################
    // START LOOP
    // ###########################
        $name=$r['name'];
        $email=$r['email'];
        $to=array(''.$email.''=>''.$name.'');
        include("hawkmail/templates/press.php");
        # Email subject
        $str=$name;
        $str=substr($str, 0, strrpos($str, ' '));
        $subject='Dear '.$str.', you are invited to our Exclusive Party Collection Press Day!';
        # send message
        include("hawkmail/settings.php");       
    }
    // ###########################
    // END LOOP
    // ###########################
}
SendEmail();
?>

该数据库有 200 条记录。我运行了脚本,它发送了几封电子邮件,然后超时

504网关超时

name记录email就像

约翰·史密斯 John.smith@site.com

很朴实。我hawkmail/settings.php的是这样的:

# mail
$smpturl="smtp.sendgrid.net";
$mailu="sitesitesite";
$mailp="sitessssssssssss";
$from=array("no-reply@site.com"=>"site.com");

# login credentials & setup Swift mailer parameters
$transport=Swift_SmtpTransport::newInstance($smpturl, 587);
$transport->setUsername($mailu);
$transport->setPassword($mailp);
$swift=Swift_Mailer::newInstance($transport);

# create a message (subject)
$message=new Swift_Message($subject);

# attach the body of the email
$message->setFrom($from);
$message->setBody($html, 'text/html');

$message->setTo($to);
$message->addPart($text, 'text/plain');

# actually send the message
if($recipients=$swift->send($message, $failures)){}else{}

无论如何要增加 PHP 超时的限制(我使用 Ubuntu 和 Nginx)或者是否有 BatchMail() 的替代品真的不明白为什么它被删除。

有人可以使用新的 swiftmailer 发布批处理邮件脚本的示例吗?

4

1 回答 1

4

发送电子邮件是网上最复杂的事情。

它是使用次数第二多的服务,也是滥用最多的服务。

我建立了自己的自定义电子邮件平台来发送批量电子邮件。

您遇到的超时是因为 Apache 和 PHP 执行限制。

您需要将其作为 CLI 应用程序运行set_time_limit (0);

php /path/to/app/script.php像这样直接在控制台中。

如果您没有 SSH 访问权限,请shell_exec像这样运行它:

shell_exec("php /path/to/app/script.php > /dev/null 2>/dev/null &");

这将确保调用它的脚本在完成之前不会挂起。

于 2012-09-01T18:34:28.380 回答