 |
php ช่วยดูโค้ดหน่อยคะส่งอีเมล์ไม้ได้คะ(พึ่งเริ่มหัดเขียน) |
|
 |
|
|
 |
 |
|
error ว่าไงครับ
|
 |
 |
 |
 |
Date :
2013-05-30 10:11:00 |
By :
Manussawin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มีerror คะแต่ echo "Email Can Not Send" ออกมาเลยไม่แน่ใจว่าเขียนโค้ดถูกไหมอ่ะคะ
|
 |
 |
 |
 |
Date :
2013-05-30 10:20:36 |
By :
Ryo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันไม่มีเออเรออยู่แล้วครับ ก็คุณเล่นใส่ @ หน้าฟังก์ชั่นนี่
ลองเอา @ ออกหน้าฟังก์ชัน mail ดูครับ แล้วดูว่ามีเออเรออะไรแจ้งมา
|
 |
 |
 |
 |
Date :
2013-05-30 12:25:22 |
By :
itpcc |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองบน Host ดูครับ หรือไม่ก็ใช้การส่งผ่าน SMTP ครับ

แจกฟรี Script ส่งอีเมล์แบบ SMTP / POP ของ PHP ที่สามารถใช้งานได้จริง ๆ
|
 |
 |
 |
 |
Date :
2013-05-30 12:26:11 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โหลดในตัวอย่างไปดูครับ มี include ไฟล์ด้วยครับ
|
 |
 |
 |
 |
Date :
2013-05-30 17:14:48 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
require_once ('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsHTML(FALSE);
$mail->IsSMTP(TRUE);
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = ""; // sets the prefix to the servier
$mail->Host = "localhost"; // sets GMAIL as the SMTP server
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "[email protected]"; // GMAIL username
$mail->Password = "thitinan"; // GMAIL password
$mail->From = $_POST["email"]; // "[email protected]";
$mail->AddReplyTo = "[email protected]"; // Reply
$mail->FromName = $_POST["name_"]; // set from Name
$mail->Subject = $_POST["title"];
$mail->Body = $_POST["msg"];
$mail->AddAddress("[email protected]","zizzee"); // to Address
$mail->Send();
?>
เขียนแบบนี้มันถูกไหมอ่ะคะ
|
ประวัติการแก้ไข 2013-05-30 17:52:03
 |
 |
 |
 |
Date :
2013-05-30 17:45:17 |
By :
Ryo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก่อนจะส่ง Email ต้องแน่ใจก่อนนะครับ ว่ามี mail server อยู่ หรือถ้าหากลองในเครื่อง ก็ต้องติดตั้งโปรแกรมจำลอง mail server ครับ เช่น argosoft mail หรือ hmailserver ในบทความก็มีนะครับวิธิการรวมถึง ขั้นตอนต่างๆ ถ้าไม่เช่นนั้นแล้วก็จะ Error อย่างนี้แหละครับ
หรือหากมี account ของ gmail ลองดูนี่ครับ แต่ต้องใช้ class phpmailer ด้วยนะครับ
Code (PHP)
<?PHP
require_once ( 'class.phpmailer.php' ); // Add the path as appropriate
$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 = 'ชื่ออีเมล์@gmail.com'; // SMTP account username
$Mail->Password = 'รหัสผ่านเข้าใช้งาน gmail'; // 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="<h3>ทดสอบส่งอีเมล์</h3>";
$Mail->Body = $MessageHTML;
//$Mail->AltBody = $MessageTEXT;
$Mail->Send();
$Mail->SmtpClose();
if ( $Mail->IsError() ) {
echo "ERROR<br /><br />";
}
else {
echo "OK<br /><br />";
}
?>
|
 |
 |
 |
 |
Date :
2013-05-30 22:10:08 |
By :
Manussawin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มาเก็บความรู้ครับ  
|
 |
 |
 |
 |
Date :
2013-05-31 02:51:13 |
By :
ความรู้น้อย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วคะ...ขอบคุณทุกคำแนะนำนะคะ
|
 |
 |
 |
 |
Date :
2013-06-03 11:45:22 |
By :
Ryo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2013-06-03 11:46:44 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|