微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – SwiftMailer批量电子邮件时间我的服务器

我意识到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 Gateway Time-out

名称和电子邮件记录就像

约翰·史密斯
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发布批量邮件脚本的示例吗?

解决方法:

发送电子邮件是在线进行的最复杂的事情.

它是第二使用最多的服务,也是滥用最多的服务.

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

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

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

PHP /path/to/app/script.PHP在控制台中就是这样.

如果您没有SSH访问权限,请使用shell_exec运行它,如下所示:

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐