2017-10-06 9 views
-2

Je suis confronté à ce problème des trois derniers jours, avant que ce script fonctionne parfaitement. Maintenant obtenir l'erreur:Échec de la connexion SMTP

SMTP ERROR: Failed to connect to server: (0) 2017-10-06 21:05:34 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message was not sent.Mailer error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting [email protected]

Voici mon script:

require 'PHPMailer/PHPMailerAutoload.php'; 

$mail = new PHPMailer; 
$mail->SMTPDebug = 2;     // Enable verbose debug output 
$mail->isSMTP();      // Set mailer to use SMTP 
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;    // Enable SMTP authentication 
$mail->Username = '[email protected]'; // SMTP username 
$mail->Password = 'mypassword';  // SMTP password 
$mail->SMTPSecure = 'tls';    // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 587; 
$mail->setFrom('[email protected]', 'Your Name'); 
$mail->addAddress('[email protected]', 'My Friend'); 
$mail->Subject = 'First PHPMailer Message'; 
$mail->Body  = 'Hi! This is my first e-mail sent through PHPMailer.'; 
if (!$mail->send()) { 
    echo 'Message was not sent.'; 
    echo 'Mailer error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent.'; 
} 

Je pense que Gmail peut avoir changé les paramètres pour l'envoi d'e-mails via SMTP, ou quelque chose comme ça.

+3

Voici une idée folle - essayez de suivre le lien dans le message d'erreur qui vous dit tout à ce sujet et comment y remédier. – Synchro

Répondre

0

Enfin, je suis en mesure d'envoyer des emails de localhost. Voici mon code.

Pour installer:

  1. Télécharger PHPMailer
  2. Ajouter à votre projet (je l'ai mis sur la racine)
  3. Ajouter classe Autoload à votre script.
  4. Reste du code est ci-dessous

     require "PHPMailer/PHPMailerAutoload.php"; 
         $mail = new PHPMailer; 
         $mail->SMTPOptions = array(
          'ssl' => array(
           'verify_peer' => false, 
           'verify_peer_name' => false, 
           'allow_self_signed' => true 
          ) 
         ); 
         //$mail->SMTPDebug = 2;         // Enable verbose debug output 
         $mail->isSMTP();          // Set mailer to use SMTP 
         $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers 
         $mail->SMTPAuth = true;        // Enable SMTP authentication 
         $mail->Username = '[email protected]';     // SMTP username 
         $mail->Password = 'securepass';       // SMTP password 
         $mail->SMTPSecure = 'ssl';       // Enable TLS encryption, `ssl` also accepted 
         $mail->Port = 465;         // TCP port to connect to 
         //Recipients 
         $mail->setFrom('[email protected]', "Mailer"); 
         $mail->addAddress("[email protected]","receiver Name"); 
         $mail->isHTML(true);         
         $mail->Subject = "Subject"; 
         $mail->Body = "Body"; 
         $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 
          if($mail->send()){ 
          return array("msg"=>msg("success","Email has been sent.<br>")); 
          } else { 
           return array("msg"=>msg("error","Email can't send.Try Again<br>")); 
          }