2016-11-05 3 views
3

Der folgende Code funktioniert auf meinem xampp lokalen Server, aber keine E-Mails auf einem Remote-Host. Ich bekomme diese Fehlermeldung:PHPMailer funktioniert nicht mit Google Mail SMTP

Message could not be sent.Mailer Error: SMTP connect() failed

require_once('header.php'); 
require_once('PHPMailer/PHPMailerAutoload.php'); 
function sendMail($address, $message){ 
    $mail = new PHPMailer; 
    //$mail->SMTPDebug = 3;     // 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 = 'mypass';    // SMTP password 
    $mail->SMTPSecure = 'tls';    // Enable TLS encryption, `ssl` also accepted 
    $mail->Port = 587;      // TCP port to connect to 
    $mail->SMTPOptions = array(
     'ssl' => array(
      'verify_peer' => false, 
      'verify_peer_name' => false, 
      'allow_self_signed' => true 
    ) 
    ); 
    $mail->setFrom('[email protected]', 'ID Test'); // Add a recipient 
    $mail->addAddress($address);    // Name is optional 
    //$mail->addReplyTo('[email protected]', 'Information'); 
    //$mail->addCC('[email protected]'); 
    //$mail->addBCC('[email protected]'); 

    $mail->isHTML(false);      // Set email format to HTML 

    $mail->Subject = 'Twitter search'; 
    $mail->Body = $message; 
    //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

    $mail->send(); 
} 
+3

http://php.net/manual/en/function.error-reporting.php --- https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting –

+1

Und es ist ein Flag debug für PHPMailer, lesen die Dokumente suchen nach ähnlichen Fragen. – Progrock

Antwort

2

ich Probleme in der Vergangenheit mit PHPMailer hatte bei Verwendung von Google Mail-Server TLS-Authentifizierungsprotokoll und Portnummer 587. Ich erinnere mich nicht, dass Kombination für mich immer arbeiten . Ich hatte jedoch nie Probleme mit SSL/465.

Statt dessen:

// Your Current Settings 
$mail->SMTPSecure = 'tls'; 
$mail->Port = 587; 

Versuchen Sie folgendes:

// Updated Settings 
$mail->SMTPSecure = 'ssl'; 
$mail->Port = 465; 

Weitere Informationen:

Verwandte Themen