|
 |
|
ช่วยดู Code เก็บชื่อ email ลง database ให้หน่อยค่ะ ว่าผิดตรงไหน เก็บได้แล้วแต่ไม่ตรงกับที่คิดไว้ |
|
 |
|
|
 |
 |
|
Code (PHP)
<?PHP
ob_start(); //ส่งข้อมูลไปเก็บไว้ที่ buffer ก่อน เมื่อได้ครบ แล้วค่อยส่งไปทีเดียว...เก็บ HTML ไว้ในตัวแปร PHP
$host="localhost";
$user="root";
$pw="mypassword";
//$pw="littlejust";
$dbname="numchai_db";
$c=mysql_connect($host,$user,$pw); //เชื่อมตอ
mysql_select_db($dbname,$c); //เลือกติดต่อกับฐานข้อมูลที่กำหนด
mysql_query("set names tis620"); //เชื่อมต่อไปเป็นภาษาไทย
if(!$c){
echo"<h3>Can't connect database!</h3>";
exit();
}
date_default_timezone_set('Asia/Bangkok');
$datetime = date("y-m-d H:i:s");
$thai_n=array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
$d=date("d");
$n=$thai_n[date("n")-1];
$y=date("Y")+543;
$t=date("H:i:s");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<div id="demo"></div>
<!-- <button onclick="myStopFunction()">Stop time</button> -->
ส่งเมล์อัตโนมัติ ทุกวัน ศุกร์ ในเวลา
<input name="timeseteday" type="text" id="timeseteday" style="width:100px; text-align:right;" value="11:16:00" />
นาฬิกา <br />
<script>
var myVar=setInterval(function(){myTimer()},1000);
function myTimer()
{
var d=new Date();
var t=d.toLocaleTimeString();
var duetime = document.getElementById('timeseteday').value;
document.getElementById("demo").innerHTML='ขณะนี้เวลา : ' + t + ' นาฬิกา';
if(t==duetime){
document.getElementById('testtimeid').innerHTML = "Yes....!";
location.reload();
}
}
function myStopFunction()
{
clearInterval(myVar);
}
///FUNCTION สำหรับโหลดเปิดหน้าเว็บขึ้นมาอีกหน้า///
function window_close()
{
window.close();
}
//----------------------------------//
</script>
<div id="testtimeid"></div>
<?PHP
$dayname[] = "'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'";
$datenow = jddayofweek(cal_to_jd(CAL_GREGORIAN, date("m"),date("d"), date("Y")) , 1 );
echo "Today is : {$datenow} <br>";
if($datenow=='Monday'){
echo "<script> window_load(); </script>"; //เรียนใช้ window_load */
$strSQL = "SELECT * FROM email";
$objResult=mysql_db_query($dbname,$strSQL);
ob_start();
require("PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSendmail(); // telling the class to use SendMail transport
$mail->CharSet = "utf-8"; //กำหนดรูปแบบตัวอักษร
$mail->IsHTML (true); //หากส่งในรูปแบบ html ถ้าส่งเป็น text ก็ลบบรรทัดนี้ออกได้
$mail->IsSMTP(); //กำหนดว่าเป็น SMTP
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true; //กำหนดให้มีการตรวจสอบสิทธิ์การใช้งาน
$mail->Host = "mail.numchai.com"; // ชื่อของเครื่องเซิร์ฟเวอร์ที่ให้บริการส่งอีเมล์ (SMTP mail server)
$mail->Port = 25; // พอร์ท 465; กำหนด port
$mail->Username = "numchai"; // account SMTP "[email protected]";
$mail->Password = "PEpanel526"; // รหัสผ่าน SMTP
$mail->SetFrom("[email protected]", "System_Autosendmail"); //ผู้ส่ง
$mail->AddReplyTo("[email protected]", "System_Autosendmail"); //ได้เมลล์แล้วตอบกลับถึงใคร
//Subject...Content หัวข้อที่ใช้ในการส่ง
//หน้าที่จะส่ง MAIL
require('content1.php');
$body = ob_get_clean(); //ได้รับข้อมูลบัฟเฟอร์ปัจจุบันและลบบัฟเฟอร์ส่งออกในปัจจุบัน
$mail->Body = $body; //ใส่เนื้อหา
$mail->MsgHTML($body);
//EMAIL...
$mail->AddAddress("[email protected]", "คุณมุก"); //ผู้รับทดสอบ
//$mail->AddAddress("[email protected]", "คุณมุก");
while ($rs=mysql_fetch_array($objResult))
{
$email=$rs['email'];
$name=$rs['name'];
//แจ้งผลการส่งMAIL
if(!$mail->Send()) { #กรณีที่ส่งเมล์ไม่ได้
if ($datenow=='Thursday'){mysql_query("INSERT INTO logfile_tb VALUES ('$email','$datetime','$datetime','Content 1','Error') ") or die(mysql_error());
echo "Mailer Error: " . $mail->ErrorInfo;
}
} else { #กรณีที่ส่งเมล์ได้
mysql_query("INSERT INTO logfile_tb VALUES ('$email',' $datetime','$datetime','Content 1','Finnish') ") or die(mysql_error());
echo "Message sent already!";
}
}}else{
mysql_query("INSERT INTO logfile_tb VALUES ('$email',' $datetime','$datetime','Content 1','Error Defalse Time') ") or die(mysql_error());
echo "Error Defalse Time";
}
mysql_close($c);
?>
<body onLoad="timer=setTimeout('window_close()',15000);">
<script>
setTimeout("testtime1()", 30000);
</script>
</body>
</html>
ตอนนี้ติดปัญหา email ที่ไปเก็บใน logfile
ส่งเมล์ไปให้แค่ 1 ชื่อ...แต่ logfile เก็บ 2 ชื่อ ตามรายชื่อในdatabase
ของเทเบิ้ล email ที่เก็บชื่อเมล์ไว้
เช่น
[email protected]
[email protected]
ส่งเมล์ไปหา A แต่ใน logfile เก็บข้อมูลทั้ง A และ B ในdatabase
ข้อมูลใน database
Table : email
เก็บ : email ([email protected],[email protected])
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2014-04-21 11:14:21 |
By :
itengineer |
View :
1542 |
Reply :
8 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตรง
Code (PHP)
while ($rs=mysql_fetch_array($objResult))
{
$email=$rs['email'];
$name=$rs['name'];
แก้เป็น
Code (PHP)
while ($rs=mysql_fetch_array($objResult))
{
$mail->ClearAddresses(); //ล้าง Email ของเดิมออก
$email=$rs['email'];
$name=$rs['name'];
$mail-AddAddress($email, $name); //เพิ่ม email จาก db
http://phpmailer.worxware.com/index.php?pg=methods
|
 |
 |
 |
 |
Date :
2014-04-21 13:03:51 |
By :
itpcc |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แค่เปลี่ยนจาก "[email protected]" เป็นเมล์ที่ได้จากฟอร์มครับ ^^~
|
 |
 |
 |
 |
Date :
2014-04-21 18:51:30 |
By :
itpcc |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|