[英]sending email to gmail account using phpmailer
<?php
require_once 'PHPMailer-master/class.phpmailer.php';
require_once 'PHPMailer-master/class.phpmaileroauthgoogle.php';
require_once 'PHPMailer-master/PHPMailerAutoload.php';
require_once 'PHPMailer-master/class.smtp.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth = TRUE;
//$mail->SMTPDebug =2;
$mail->Host = 'smtp.gmail.com';
$mail->Username = 'zhaider113@gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 587;
$from = 'shahghafoor439@gmail.com';
$mail->setFrom($from, 'Ghafoor Shah');
$mail->addReplyTo($from, 'Ghafoor Shah');
$mail->addAddress('zhaider113@gmail.com', 'zeeshan');
$mail->Subject = 'This is subject';
$mail->Body = 'This is the body of email';
$mail->AltBody = 'This is the body of email';
$mail->send();
if (!$mail->send()) {
echo 'Messag could not send';
echo 'Mailer error:' . $mail->ErrorInfo;
} else {
echo 'mail hasbeen send';
}
?>
我嘗試發送電子郵件,但未發送並給出錯誤消息:SMTP connect()失敗。 https://github.com/PHPMailer/PHPMailer/wiki/故障排除 * /
嘗試使用$mail->SMTPSecure = 'tls';
在下面的PHPMailer的gmail示例中查看完整的示例: https : //github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps
確保您包括正確的PHPMailer庫。
並進行更改
某些服務器不響應SSL(安全)。 從而更改此
$mail->SMTPSecure = 'tls';
在您的代碼中,您有兩個Mail發送選項
$mail->send();
//$mail->send();//Comment this
if (!$mail->send()) {
echo 'Messag could not send';
echo 'Mailer error:' . $mail->ErrorInfo;
} else {
echo 'mail hasbeen send';
}
現在, 要么發送郵件,要么要么 打印錯誤日志
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.