แบบแรกลองตรวจสอบว่าหมายเลข PORT ของ Mail Server ถูกหรือเปล่าต้องกำหนดให้ถูก
แบบที่ 2 Gmail ล่าสุด PORT ได้เปลี่ยนจาก 465 เป็น 587 แล้วแต่ผมยังไม่ได้ลองในปัจจุบัน ยังไงให้กำหนดค่าตามข้างล่างนะครับ (ได้ผลยังไงบอกด้วยนะครับ)
Code (PHP)
$Mail = new PHPMailer();
$Mail->IsSMTP(); // Use SMTP
$Mail->Host = "smtp.gmail.com"; // Sets SMTP server
$Mail->SMTPDebug = 2; // 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE; // enable SMTP authentication
$Mail->SMTPSecure = "tls"; //Secure conection
$Mail->Port = 587; // set the SMTP port
$Mail->Username = ''; // SMTP account username
$Mail->Password = ''; // SMTP account password
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = 'Test Email Using Gmail';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = ''; //ผู้ส่ง
$Mail->FromName = 'ทดสอบ';
$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$ToEmail=""; //ผู้รับ
$Mail->AddAddress($ToEmail); // To:
$Mail->isHTML( TRUE );
$MessageHTML="ทดสอบ";
$Mail->Body = $MessageHTML;
//$Mail->AltBody = $MessageTEXT;
$Mail->Send();
$Mail->SmtpClose();
if ( $Mail->IsError() ) {
echo "ERROR<br /><br />";
}
else {
echo "OK<br /><br />";
}
ERROR ดังนี้เลยครับ User Pass ผมลองหลาย Account มากแต่ผลก็เหมือนกันเลยครับ
Server ตัวแรก Code
SMTP -> FROM SERVER:220 mx.google.com ESMTP qk7sm37350093igc.8 - gsmtp
SMTP -> FROM SERVER: 250-mx.google.com at your service, [174.122.93.66] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250 CHUNKING
SMTP -> FROM SERVER:220 2.0.0 Ready to start TLS
SMTP -> FROM SERVER: 250-mx.google.com at your service, [174.122.93.66] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN 250-ENHANCEDSTATUSCODES 250-PIPELINING 250 CHUNKING
SMTP -> ERROR: Password not accepted from server: 534-5.7.9 Please log in with your web browser and then try again. Learn more at 534 5.7.9 https://support.google.com/mail/bin/answer.py?answer=78754 qk7sm37350093igc.8 - gsmtp
SMTP Error: Could not authenticate. SMTP -> FROM SERVER:221 2.0.0 closing connection qk7sm37350093igc.8 - gsmtp
ERROR
Server ตัวสอง Code
SMTP -> FROM SERVER:220 mx.google.com ESMTP q7sm53111889pbc.20 - gsmtp
SMTP -> FROM SERVER: 250-mx.google.com at your service, [122.155.1.87] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250 CHUNKING
SMTP -> FROM SERVER:220 2.0.0 Ready to start TLS
SMTP -> FROM SERVER: 250-mx.google.com at your service, [122.155.1.87] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN 250-ENHANCEDSTATUSCODES 250 CHUNKING
SMTP -> ERROR: Password not accepted from server: 534-5.7.9 Please log in with your web browser and then try again. Learn more at 534 5.7.9 https://support.google.com/mail/bin/answer.py?answer=78754 q7sm53111889pbc.20 - gsmtp
SMTP -> FROM SERVER:250 2.1.5 Flushed q7sm53111889pbc.20 - gsmtp
SMTP Error: Could not authenticate. SMTP -> FROM SERVER:221 2.0.0 closing connection q7sm53111889pbc.20 - gsmtp
ERROR
$mail = new PHPMailer();
$mail->CharSet = "utf-8";
$mail->IsHTML(true);
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "173.194.79.108"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "[email protected]"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->From = "[email protected]"; // "[email protected]";
//$mail->AddReplyTo = "[email protected]"; // Reply
$mail->FromName = "Name"; // set from Name
$mail->Subject = "Subject";
#--------------------------------------Set Body E-mail----------------------------------#
$message = " You have a new message! ";
$mail->Body = $message;
$mail->AddAddress("[email protected]", "Name"); // to Address
#$mail->AddAttachment("thaicreate/myfile.zip");
#$mail->AddAttachment("thaicreate/myfile2.zip");
//$mail->AddCC("[email protected]", "Mr.Member ShotDev"); //CC
//$mail->AddBCC("[email protected]", "Mr.Member ShotDev"); //CC
$mail->set('X-Priority', '3'); //Priority 1 = High, 3 = Normal, 5 = low
if ($mail->Send()){
msg('Your message has been sent!');
} else {
msg('Oops! \n\n Due to an unknown error, your form was not submitted, \nplease resubmit it or try later.');
}