|
 |
|
ถึง คุณ Avrill รบกวนอทิบาย โค้ด ส่วนนี้ให้ผมฟังทีได้ไหมครับ ผมดู ศึกษา โค้ดคุณมา ซักพักแล้ว |
|
 |
|
|
 |
 |
|
เขียนแบบนี้ท่าจะผิดนะครับเนี่ย น่าจะแบบนี้มากว่า
เลือก member id แล้ว วน loop ตามค่า array $_POST["chkMembers"] ที่ส่งมา
foreach($_POST["chkMembers"] as $i=>$v)
{
if($_POST["chkMembers"][$i] != ""){
$strSQL = "select * from tb_memtest ";
$strSQL .="WHERE memberID ='".$_POST["chkMembers"][$i]."' ";
$result = mysql_db_query($database,$strSQL);
while($members= mysql_fetch_array($result)){
$to_name ="".$members[memberName]."";
$to_email ="".$members[memberEmail]."";
$from_name ="เยาวลักษณ์";
$email_user_send ="[email protected]";
$email_pass_send ="123456789";
$subject ="หัวข้อ Email";
$body_html = file_get_contents('contents.html');
$body_html = eregi_replace("[\]",'',$body_html);
//echo $body_html;
sendmail($to_name,$to_email,$from_name,$email_user_send,$email_pass_send,$subject,$body_html);
echo "<div align=\"left\">".$to_email.":<span style=\"color:red; font-size:11px;\">Successfully</span></div>";
} //End loop while
}
}
|
 |
 |
 |
 |
Date :
2010-01-08 10:35:44 |
By :
thaiitcertified |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่า ขอบคุณครับ แต่ผมยังไม่เข้าใจคอนเซปโปรแกรมเลยอะครับ
|
 |
 |
 |
 |
Date :
2010-01-08 10:54:38 |
By :
Hello World |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้โค๊ดที่แก้ไขแล้ว ใช้งานอยู่ค่ะ
สงสัยตรงใหนบ้างถามได้ค่ะ
อธิบายไม่ค่อยเก่งค่ะ ผิดถูกประการใดขออภัยด้วยนะค่ะ
Code (PHP)
<?
include ("class.phpmailer.php"); // include class phpmailer เข้ามาค่ะ
$path="../";
include ($path.'include/config.php'); // config เชื่อมต่อฐานข้อมูลค่ะ
function sendMail($to_name,$to_email,$from_name,$email_user_send,$email_pass_send,$subject,$body_html) {
$mail = new PHPMailer();
$mail -> From = $email_user_send;
$mail -> FromName = $from_name;
$mail -> AddAddress($to_email,$to_name);
$mail -> Subject = $subject;
$mail -> Body = $body_html;
$mail -> AltBody = $body_text;
$mail -> IsHTML (true);
$mail->IsSMTP();
$mail->Host = 'ssl://smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
//$mail->SMTPDebug = true;
$mail->Username = $email_user_send;
$mail->Password = $email_pass_send;
$mail->Send();
$mail->ClearAddresses();
}
$op =$_REQUEST['btnSend'];
$sbjTxt=stripcslashes($_POST['subject']);
if($op=="sendmail"){ //ถ้ามีการเลือกรายชื่ออีเมลล์จาก checkbox
//วนลูปรายชื่อ อีเมล์ที่เลือกจาก Checkbox
for($i=0;$i<count($_POST["chkMembers"]);$i++)
{
if($_POST["chkMembers"][$i] != "")
{
$strSQL = "select * from tb_members "; //select สมาชิกจาก ตารางข้อมูล
$strSQL .="WHERE memberID ='".$_POST["chkMembers"][$i]."' "; // where ไปยังสมาชิกที่เราเลือกจาก Checkbox
$result = mysql_db_query($database,$strSQL);
//เริ่มการวนลูป ส่งอีเมล์ไปยังสมาชิกทีละคน
while($members= mysql_fetch_array($result)){
$to_name ="".$members[memberName].""; // ชื่อของสมาชิกที่จะส่งเมลล์ไป ได้จาก ฟิลด์ memberName
$to_email ="".$members[memberEmail].""; // อีเมลล์ของสมาชิก
$from_name ="เยาวลักษณ์";// ชื่อผู้ส่ง
$email_user_send ="[email protected]"; //เมลล์ของเรา ต้องเป็น Gmail หรือ google apps
$email_pass_send ="123456789"; // Password
$subject =$sbjTxt; //หัวข้ออีเมลล์ ได้จากตัวแปร $sbjTxt POST ข้อความจาก input text
$body_html = file_get_contents('contents.html'); //เนื้อหาของอีเมลล์ เป็น html สร้างไฟล์ content.html ขึ้นมาค่ะ
$body_html = eregi_replace("[\]",'',$body_html);
sendMail($to_name,$to_email,$from_name,$email_user_send,$email_pass_send,$subject,$body_html);
//แสดงสถานะ ว่าส่งเสร็จแล้ว
echo "<div align=\"center\">".$to_email.":<span style=\"color:red; font-size:11px;\">Successfully</span></div>";
}
}
}
echo"<br>";
echo "<div align=\"center\"><form><input type=button value=\"History Back\" onclick=\"history.go(-1);\"></form></div>";
}
?>
|
 |
 |
 |
 |
Date :
2010-01-08 13:15:42 |
By :
Avrill |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่าขอบคุณครับ
|
 |
 |
 |
 |
Date :
2010-01-08 14:36:29 |
By :
Hello World |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
if($op=="sendmail"){ //ถ้ามีการเลือกรายชื่ออีเมลล์จาก checkbox
บันทัดนี้ ถ้า $op=="sendmail" sendmail คืออะไรครับ ฟังชั่น send mail หรอครับแล้วถ้าหาก ฟังก์ชั่นผมเป็นแบบนี้ จะทำยังไงหรอครับผม
Code (PHP)
<?
}//ปิดลูป while
$op =$_REQUEST['choose'];
$sbjTxt=stripcslashes($_POST['subject']);
// ส่งไปทีอีเมลไหน โดย ที่อ้างอิง จาก บันทัดที่ 159 นะ ส่งไปตามที่ user กรอก
$strTo = $_POST["email"];
// หัวข้อ ดึงจากดาต้าเบส จากฟิลด์ ที่เทเบิล jos_joe_dailymessage
$strSubject = $NameProgram;
$strHeader = "Content-type: text/html; charset=windows-874\n"; // or UTF-8 //
$MailFrom = $EmailAdmin;
$strHeader .= "From: ".$MailFrom." <".$MailFrom.">";
$strMessage = $UrlDownload;
$flgSend = @mail($strTo,$strSubject,$strMessage,$strHeader,$MailFrom); // @ = No Show Error //
mysql_close($objconnect);
?>
|
 |
 |
 |
 |
Date :
2010-01-15 09:21:09 |
By :
Behavior |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|