2016-04-05 14 views
0

Ich habe versucht, eine E-Mail mit SMTP-Server in PHP-Mailer-Funktion zu senden.SMTP-Mail-Trigger funktioniert nicht

Das war der Fehler, wenn ich das ausgelöst habe.

Ich verwende den Gmail-Mail-Server.

SMTP-Verbindung() fehlgeschlagen.

require_once(TEMPLATEPATH . '/PHPMailer-master/PHPMailerAutoload.php'); 
$mail = new PHPMailer; 
//Tell PHPMailer to use SMTP 
$mail->isSMTP(); 
//Enable SMTP debugging 
// 0 = off (for production use) 
// 1 = client messages 
// 2 = client and server messages 
$mail->SMTPDebug = 2; 
//Ask for HTML-friendly debug output 
$mail->Debugoutput = 'html'; 
//Set the hostname of the mail server 
$mail->Host = "smtp.gmail.com"; 
//Set the SMTP port number - likely to be 25, 465 or 587 
$mail->Port = 25; 
//Whether to use SMTP authentication 
$mail->SMTPAuth = true; 
//Username to use for SMTP authentication 
$mail->Username = "xxxx"; 
//Password to use for SMTP authentication 
$mail->Password = "xxxx"; 
//Set who the message is to be sent from 
$mail->setFrom('xxxx', 'First Last'); 
//Set an alternative reply-to address 
$mail->addReplyTo('xxxxx', 'First Last'); 
//Set who the message is to be sent to 
$mail->addAddress('xxxx', 'John Doe'); 
//Set the subject line 
$mail->Subject = 'PHPMailer SMTP test'; 
$mail->msgHTML('test'); 

$mail->AltBody = 'This is a plain-text message body'; 
//Attach an image file 


//send the message, check for errors 
if (!$mail->send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 

Dies ist mein Code. Bitte schlagen Sie vor, was ist der Fehler in meinem Code oder wo zu smtp Verbindung fehlgeschlagen Fehler überprüfen.

Vielen Dank im Voraus.

+0

alles in php_error? – Random

+0

@Random keine PHP-Fehler –

+0

gehören 'class.phpmailer.php' nicht die, die Sie einschließlich –

Antwort

1

Nun, das ist, warum es nicht funktionierte,
php.ini Öffnen und für diese Linie suchen; extension = php_openssl.dll und das Semikolon, bevor es entfernen, um die Datei speichern und den Webserver neu starten. Sie werden sehen, dass Ihr Code funktioniert, nachdem Sie diese Änderung vorgenommen haben.

und stellen Sie Ihre Host wie folgt:

$mail->Host = "ssl://smtp.gmail.com"; 
+0

Ich versuchte dies auch, aber nicht für mich arbeiten –

Verwandte Themen