我使用PHPMailer发送每日电子邮件(最多100封电子邮件),我的脚本在本地工作正常,但是当我将它上载到我的服务器(托管在OVH)时,和发送的20个电子邮件PHPMailer smtp连接()在ovh服务器上失败
SMTP connect() failed https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
平均后产生这个错误
我联系OVH他们难过了,有一个与我的电子邮件住址没有问题,所以我认为这是对我的代码中的bug,这里是我的代码:
$m = new PHPMailer;
$mail = new Mailing();
$admin = new Administrateur();
$m->isSMTP();
$m->IsHTML(true);
$m->SMTPAuth = true;
$m->SMTPDebug = 0;
$m->SMTPKeepAlive = true;
$m->Host = 'ssl0.ovh.net';
$m->Username = '[email protected]';
$m->Password = 'xxxxxxxxxxx';
$m->SMTPSecure = 'ssl';
$m->Port = "465";
$m->CharSet = 'UTF-8';
$m->From = '[email protected]';
$m->FromName = 'Chantier TN';
$m->addReplyTo('[email protected]', 'Reply adress');
$m->Subject = 'Alerte quotidienne';
$error = false;
$alertes = Session::get('alertes');
$date = date('Y-m-d h:i:s');
$token = $alertes[$id]['id_cli'].'-'.strtotime($date);
$m->addAddress($alertes[$id]['email'], strtoupper($alertes[$id]['nom']).' '.$alertes[$id]['prenom']);
Session::delete('send');
$m->Body = $mail->generateBodyForAlerte(strtoupper($alertes[$id]['nom']).' '.$alertes[$id]['prenom'], $alertes[$id]['leads'], $token);
if ($m->send()) {
$mail->set('type_mail', 1);
$mail->set('date_send', $date);
$mail->set('id_cli', $alertes[$id]['id_cli']);
$mail->set('id_op', $admin->getId());
$mail->set('content', Session::get('send'));
$mail->save();
$s = Session::exists('sent') ? Session::get('sent') : array();
$s[] = $alertes[$id]['email'];
Session::put('sent', $s);
}
else{
$error = $m->ErrorInfo;
$s = Session::exists('notsend') ? Session::get('notsend') : array();
$s[] = $alertes[$id]['email'].' error: '.$error;
Session::put('notsend', $s);
}
$m->clearAddresses();
if (!isset($_SESSION['alertes'][$id+1])) {
$next = false;
}
else{
$next = $id+1;
}
电子邮件列表存储在一个会话循环与id,我从你的id l使用mvc结构,执行此代码后,我呈现一个显示已发送邮件列表的视图,如果发生错误,我会用错误回复电子邮件地址,5秒钟后,我将重定向到具有下一个ID的同一页面使用jquery。 这里是输出的图片:
亚历克斯的答案是现货 - 但是,你是否发现你要遵循错误信息中的链接?它就在你的面前! – Synchro