Problème avec l'authentification SMTP en PHP à l'aide de PHPMailer, avec de la Poire Mail fonctionne
Im avoir mal à l'envoi d'un e-mail avec la classe PHPMailer, mais il fonctionne avec de la POIRE Courrier::factory.
Je crois que le problème est avec l'authentification SMTP, mais je ne pourrais pas trouver le problème.
Le code avec le problème de l'est:
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); //set mailer to use SMTP
$mail->Host = 'mail.xxx.com.br'; //my host here
$mail->SMTPAuth = true; //turn on SMTP authentication
$mail->Username = '[email protected]'; //a valid email here
$mail->Password = '***'; //the password from email
$mail->From = '[email protected]';
$mail->SMTPDebug = true;
$mail->AddReplyTo('[email protected]', 'Test');
$mail->FromName = 'Test SMTP';
$mail->AddAddress('[email protected]', '[email protected]');
$mail->Subject = 'Test SMTP';
$mail->IsHTML(true);
$mail->Body = '<b>Teste</b><br><h1>teste 2</h1>';
//$mail->Send();
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
?>
Le code avec de la POIRE qui fonctionne est:
<?php
include('Mail.php');
include('Mail/mime.php');
$text = 'Versao em texto';
$html = '<html><body>Versao de email em <b>HTML</b></body></html>';
$crlf = "\n";
$hdrs = array(
'From' => '[email protected]',
'Subject' => 'Test - mail.php'
);
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail = Mail::factory('smtp',
array ('host' => 'mail.xxx.com.br',
'debug'=> true,
'auth' => true,
'username' => '[email protected]',
'password' => '***'));
$mail->send('[email protected]', $hdrs, $body);
?>
Lorsque j'exécute le code avec problème de débogage activé (SMTPDebug = True) j'ai eu:
SMTP -> FROM SERVER:
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
"
SMTP -> get_lines(): $data is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
"
SMTP -> get_lines(): $data was "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
"
SMTP -> get_lines(): $str is "220-We do not authorize the use of this system to transport unsolicited,
"
SMTP -> get_lines(): $data is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
"
SMTP -> get_lines(): $data was "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
"
SMTP -> get_lines(): $str is "220 and/or bulk e-mail.
"
SMTP -> get_lines(): $data is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
"
SMTP -> FROM SERVER:
220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
SMTP -> ERROR: EHLO not accepted from server: 220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> get_lines(): $str is "250-SIZE 20971520
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
"
SMTP -> get_lines(): $str is "250-PIPELINING
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
"
SMTP -> get_lines(): $str is "250-AUTH PLAIN LOGIN
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
"
SMTP -> get_lines(): $str is "250-STARTTLS
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
"
SMTP -> get_lines(): $str is "250 HELP
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
"
SMTP -> FROM SERVER:
250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250 orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> get_lines(): $data is "250 orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> ERROR: AUTH not accepted from server: 250 orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "503 AUTH command used when not advertised
"
SMTP -> get_lines(): $data is "503 AUTH command used when not advertised
"
SMTP -> FROM SERVER:
503 AUTH command used when not advertised
SMTP -> ERROR: RSET failed: 503 AUTH command used when not advertised
Message could not be sent. <p>Mailer Error: SMTP Error: Could not connect to SMTP host.
Et le déboguer le résultat de la POIRE Mail code est:
DEBUG: Recv: 220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Tue, 04 Aug 2009 19:37:10 -0300
DEBUG: Recv: 220-We do not authorize the use of this system to transport unsolicited,
DEBUG: Recv: 220 and/or bulk e-mail.
DEBUG: Send: EHLO localhost
DEBUG: Recv: 250-orion.bommtempo.net.br Hello localhost [200.155.129.6]
DEBUG: Recv: 250-SIZE 20971520
DEBUG: Recv: 250-PIPELINING
DEBUG: Recv: 250-AUTH PLAIN LOGIN
DEBUG: Recv: 250-STARTTLS
DEBUG: Recv: 250 HELP
DEBUG: Send: STARTTLS
DEBUG: Recv: 220 TLS go ahead
DEBUG: Send: EHLO localhost
DEBUG: Recv: 250-orion.bommtempo.net.br Hello localhost [200.155.129.6]
DEBUG: Recv: 250-SIZE 20971520
DEBUG: Recv: 250-PIPELINING
DEBUG: Recv: 250-AUTH PLAIN LOGIN
DEBUG: Recv: 250 HELP
DEBUG: Send: AUTH LOGIN
DEBUG: Recv: 334 VXNlcm5hbWU6
DEBUG: Send: c2lzdGVtYWFkbWluQGJvbW10ZW1wby5jb20uYnI=
DEBUG: Recv: 334 UGFzc3dvcmQ6
DEBUG: Send: RVkyYVM4YnpMNU5k
DEBUG: Recv: 235 Authentication succeeded
DEBUG: Send: MAIL FROM:
DEBUG: Recv: 250 OK
DEBUG: Send: RCPT TO:
DEBUG: Recv: 250 Accepted
DEBUG: Send: DATA
DEBUG: Recv: 354 Enter message, ending with "." on a line by itself
DEBUG: Send: MIME-Version: 1.0
From: sistemaadmin@bommtempo.com.br
Subject: Teste de mail - mail.php
Content-Type: multipart/alternative;
boundary="=_b3c5407ccf494306d78fbb35800efe65"
--=_b3c5407ccf494306d78fbb35800efe65
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="ISO-8859-1"
Versao em texto
--=_b3c5407ccf494306d78fbb35800efe65
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="ISO-8859-1"
Versao de email em HTML--=_b3c5407ccf494306d78fbb35800efe65--
.
DEBUG: Recv: 250 OK id=1MYSd4-0005Ky-Jw
DEBUG: Send: QUIT
OriginalL'auteur Evandro | 2009-08-05
Vous devez vous connecter pour publier un commentaire.
étrange problème que j'ai résolu en commentaire cette ligne
de pentecôte, le dernier phpmailer version (5.2)
Cela se produit lorsque commentaire cette ligne: impossible d'instancier la fonction mail. Mailer Erreur: impossible d'instancier la fonction mail.
Lorsque commentant la ligne
$mail->IsSmtp();
le courrier ne seront pas envoyés à l'aide de SMTP.il utiliser localhost au lieu de SMTP peut-être ?
je confirme que cela a résolu mon problème.
OriginalL'auteur maurox
Essayez d'ajouter ceci:
En regardant vos journaux de débogage, vous pouvez remarquer que le défaut de PhpMailer journal affiche ceci:
Alors que le succès de votre POIRE journal affiche ceci:
Ma conjecture est que explicitement demandé PHPMailer pour utiliser TLS le mettra sur la bonne voie.
Aussi, assurez-vous que vous utilisez la dernière versin de PHPMailer.
OriginalL'auteur Carlos Lima
Ce qui m'est arrivé. Pour moi, Postfix était situé sur le même serveur que le script PHP, et l'erreur qui se passait quand je serais à l'aide de l'authentification SMTP et smtp.domain.com au lieu de localhost.
Alors, quand j'ai commenté ces lignes:
$mail->SMTPAuth = true;$mail->SMTPSecure = "tls";et de définir l'hôte de
au lieu
$mail->Host = 'smtp.mydomainiuse.com'et cela a fonctionné 🙂
OriginalL'auteur Dushan Savich
que l'extension OpenSSL activé et que le répertoire de langues par "br"?
vérifie d'abord les données.
OriginalL'auteur andres descalzo
Exim 4 exige que AUTH commande ne sera envoyée qu'après que le client a émis EHLO - tente de s'authentifier sans EHLO serait rejetée. Certains serveurs d'email exiger que EHLO être publié deux fois. PHPMailer, apparemment, ne parvient pas à le faire. Si PHPMailer ne vous permet pas de force EHLO initiation, vous devriez vraiment passer à SwiftMailer 4.
OriginalL'auteur mst
Vérifier si vous avez défini restreindre sortant SMTP uniquement à certains utilisateurs du système (root, MTA, mailman,...). Cette restriction peut empêcher les spammeurs, mais va rediriger les connexions SMTP sortantes du serveur de courrier local.
OriginalL'auteur Pedro Correia Sardinha