2016-04-05 5 views
0

phpメーラー機能でsmtpサーバーを使用してメールを送信しようとしました。SMTPメールトリガーが動作していません

これは私がこれを引き起こしたときのエラーです。

Gmailメールサーバーを使用しています。

SMTP connect()に失敗しました。

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!"; 
} 

これは私のコードです。私のコードに間違いがあるか、smtp接続のエラーをどこでチェックするのかを教えてください。

ありがとうございました。拡張子= php_openssl.dllと、その前にセミコロンを削除し、ファイルを保存し、あなたのウェブサーバを再起動します。

+0

何か? – Random

+0

@ランダムなPHPエラー –

+0

には 'class.phpmailer.php'は含まれていません –

答えて

1

まあ、それはそれが機能しなかった理由を、
があなたのphp.iniを開き、次の行を探します。この変更を行った後、コーディングが動作することがわかります。

と次のようにホストを設定します。php_errorで

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

私もこれを試しましたが、私のために働いていません –

関連する問題