 |
ทำไมถึงส่งอีเมล์เข้าเมล์ด้วย PHP ไม่ได้ครับ งง มากๆ |
|
 |
|
|
 |
 |
|
แบบแรกลองตรวจสอบว่าหมายเลข 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 />";
}
|
ประวัติการแก้ไข 2013-12-26 14:36:16
 |
 |
 |
 |
Date :
2013-12-26 14:35:45 |
By :
Manussawin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กำหนดตามนี้เลยครับ ผมเพิ่งเพิ่มเข้าไปในระบบเมื่อวานเอง ใช้งานได้ปกติ
Code (PHP)
$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.');
}
|
ประวัติการแก้ไข 2013-12-26 15:03:00
 |
 |
 |
 |
Date :
2013-12-26 15:01:23 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณ run บนโฮสจิงหรือในเครื่องครับ สคริปนี้ผม run บนโฮสจิง ไม่มีปัญหาใดๆ ทั้งสิ้น 
|
 |
 |
 |
 |
Date :
2013-12-26 15:37:50 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รันบนโฮสจริง ครับ ผมลองบน 2 โฮสเลยครับ
|
 |
 |
 |
 |
Date :
2013-12-26 15:38:40 |
By :
bannanai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ปัญหาคือเป็นโฮสที่ผมเช่าครับ ผมไม่สามารถไป Config อะไรได้เลยครับ
เมื่อก่อนผมเคยใช้ฟังก์ชัน mail ธรรมดาๆ นี่แหละครับ ยังใช้ได้เลยบนโฮสตัวนี้
แต่ตอนนี้ใช้ไม่ได้เลยสักกรณี ไม่แน่ใจว่าเป็นที่ Config Server หรือปล่าว เพราะผมลองบนโฮสที่เช่าไว้อีกตัวก็ไม่ได้เหมือนกัน
|
 |
 |
 |
 |
Date :
2013-12-26 16:14:58 |
By :
bannanai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|