當我嘗試使用PHP SMTP電子郵件服務器發送電子郵件時,發生以下錯誤。SMTP錯誤:無法驗證。消息無法發送。郵件錯誤:SMTP錯誤:無法驗證
SMTP Error: Could not authenticate. Message could not be sent.
郵件錯誤:SMTP錯誤:無法驗證。
以下是我用過的代碼。
function supervisorMail(){
global $error;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = "***@gmail.com";
$mail->Password = "****";
$mail->SetFrom("***@gmail.com", "Employee Leave Management System");
$userID=$_SESSION['userID'];
$select_query = mysql_query("SELECT * FROM employee WHERE emp_id = '$userID'");
$select_sql = mysql_fetch_array($select_query);
$name=$select_sql['manager_name'];
var_dump($name);
$select_query1 = mysql_query("SELECT email FROM employee WHERE emp_id='$name'");
$select_sql1 = mysql_fetch_array($select_query1);
$email=$select_sql1['email'];
var_dump($email);
$mail->Subject = "subject ";
$mail->Body = "something.";
$mail_to = $email;
$mail->AddAddress($mail_to);
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
}
我該如何解決了這個錯誤。
檢查我的答案,並嘗試http://stackoverflow.com/questions/37518499/could-not-connect-to-smtp-host-message-could-not-be-sent/37523865#37523865 –
進入** $ mail->用戶名**和密碼** ** mail->密碼** –