2016-01-21 78 views
1

我使用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。 这里是输出的图片: enter image description here

+0

亚历克斯的答案是现货 - 但是,你是否发现你要遵循错误信息中的链接?它就在你的面前! – Synchro

回答

1

由于docs点出:

"SMTP Error: Could not connect to SMTP host."

This may also appear as SMTP connect() failed or Called Mail() without being connected in debug output. This is often reported as a PHPMailer problem, but it's almost always down to local DNS failure, firewall blocking or other issue on your local network. It means that PHPMailer is unable to contact the SMTP server you have specified in the Host property, but doesn't say exactly why. It can also be caused by not having the openssl extension loaded (See encryption notes below).

所以我的建议是设置:

$m->SMTPDebug = 4; 

以获得更详细的信息和变化一旦找出原因,请回到0

在这里发布扩展调试信息,所以我们可以进一步研究它。

调试信息(从评论 - 删除时间戳):

SERVER -> CLIENT: 250-ns0.ovh.net You connect to mail751 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-8BITMIME 250 SIZE 109000000
Auth method requested: UNKNOWN
Auth methods available on the server: LOGIN,PLAIN
Auth method selected: LOGIN
CLIENT -> SERVER: AUTH LOGIN
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "334 VXNlcm5hbWU6 "
SERVER -> CLIENT: 334 VXNlcm5hbWU6
CLIENT -> SERVER: bm9yZXBseUBjaGFudGllci50bg==
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "334 UGFzc3dvcmQ6 "
SERVER -> CLIENT: 334 UGFzc3dvcmQ6
CLIENT -> SERVER: Y2luMjM0NjQ4ODQ=
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "535 authorization failed (#5.7.0) "
SERVER -> CLIENT: 535 authorization failed (#5.7.0)
SMTP ERROR: Password command failed: 535 authorization failed (#5.7.0)
SMTP Error: Could not authenticate.
CLIENT -> SERVER: QUIT
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "221 ns0.ovh.net You connect to mail751 "
SERVER -> CLIENT: 221 ns0.ovh.net You connect to mail751
Connection: closed

所以,很显然,OVH不验证你。也许ovh以某种方式限制你的速度?

+0

本来会做出这样的评论,但它不适合。 –

+0

如何在页面重新载入后获得调试信息?错误有时候通常不会出现 – RaisoMos

+0

输出应该在'$ m-> ErrorInfo'中。你已经将它存储在'$ _SESSION'中; –

相关问题