Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > สอบถามเรื่องการเขียน Function mail และ loop ข้อมูลออกมาเพื่อส่ง



 

สอบถามเรื่องการเขียน Function mail และ loop ข้อมูลออกมาเพื่อส่ง

 



Topic : 066700

Guest




สอบถามเรื่องการเขียน Function mail และ loop ข้อมูลออกมาเพื่อส่ง

หลักๆก็คือ ผมเขียน Fuction mail ขึ้นมา ตามตัวอย่าง Code ด้านล่าง

จุดประสงค์คือ ส่งเมลล์แจ้งลูกค้า เมื่อมีการสั่งซื้อสินค้า

ทำการเรียกใช้ Function mail และใน Function เขียน Loop เพื่อให้แสดงข้อมูลทั้งหมดที่ลูกค้าสั่งซื้อมา และทำการส่งเมลล์แจ้ง

แต่ จากที่ลองทำแล้ว ติดในส่วนของ Loop ข้อมูล

ขอคำแนะนำหน่อยครับว่าจะเขียนในลักษณะไหนดี ถึงจะสามารถใช้งานได้

ซึ่งตอนนี้ทำให้เมลล์สามารถส่งออกได้แล้ว แต่ส่งได้เฉพาะข้อมูลสินค้าตัวล่าสุดท้ายอย่างเดียว


Code (PHP)
function send_out($email,$uid,$pid) // Mail แจ้งข้อมูลลืมรหัสผ่าน
{	
	$userdt=getUserById($uid);	
		
	$ad_mail = admin_email();
	$to=$email;
	$rec=mysql_fetch_array(mysql_query("select forget_mail from admin_mail"));
	$sub=_MOMS_TEAM_." - "._SEND_OUT_;

$toz=mysql_query("select * from `order` where id='016700' limit 1");
if($ro=mysql_fetch_array($toz));
else {
	echo '<b>ไม่พบข้อมูลที่ต้องการ</b>';
	}
	
$tl=mysql_query("select * from orderlist where oid='016700' order by id");
$arr1=array();
$list=array();
while($x=mysql_fetch_array($tl))
	{
	$list[$x[id]]=$x;
	$arr1[$x[pid]]=$x[pid];
	}
$pids=implode(',', $arr1);

$plist=array();
if($pids!='')
	{
	$tp=mysql_query("select id,pcode,instock from product where id in ($pids)");
	while($x=mysql_fetch_array($tp))
		$plist[$x[id]]=$x;
	}

if($ro[uid]>0)
	{
	$td=mysql_query("select id,username from dealer where id='{$ro[uid]}' limit 1");
	if($rd=@mysql_fetch_assoc($td))
		{
		}
	}

$tm=mysql_query("select * from payment order by onum");

/*if($rd[username]!=''){ $l= '<th align='left'>Username </th><td align='left'>'.$rd[username].'</td>'; } else { '<th align='left'>พนักงานขาย </th><td align='left'>'.$ro[saleman].'</td>'; };*/
if($rd[username]!=''){ $l= '<tr><th align=\'left\'>Username </th><td align=\"left\">'.$rd[username].'</td></tr>'; } else { $l= '<tr><th align=\"left\">พนักงานขาย </th><td align=\"left\">'.$ro[saleman].'</td></tr>'; };

$totalprice=0;
$tz= foreach($list as $x){
	$sumprice=$x[qty]*$x[price];
	$totalprice+=$sumprice;
	$ll= "<tr><td width='200'>'.$plist$x[pid][pcode].'</td><td width='350'>'.$x[name].'</td><td width='200'>'.number_format($x[price],2).'</td><td width='200'>'.$x[qty].'</td><td width='200'>'.number_format($sumprice,2).'</td></tr>";
	};


	$body="<table width='100%'>
	<tr valign='top'>
		<td>
			<div style='font-size:18pt; font-weight:bold;'>
				CYBERBATT
			</div>
			<div style='font-size:18pt; font-weight:bold;'>
				ใบสั่งซื้อ
			</div>
		</td>
		<td align='right'>
			<table style='font-size:12pt;'>
				<tr><th align='left'>ใบสั่งสินค้าเลขที่</th><td align='left'><b>016700</b></td></tr>
				<tr><th align='left'>ผู้สั่งซื้อ </th><td align='left'>$ro[name]</td></tr>
				$l
			</table>
		</td>
	</tr>
</table>
<table cellspacing='0' cellpadding='2' class='sptb1' >
<tr bgcolor='#66CC99'>
	<th>รหัสสินค้า</th>
	<th>ชื่อสินค้า</th>
	<th align='right'>ราคา/หน่วย</th>
	<th align='center'>จำนวน</th>
	<th align='right'>ราคารวม</th>
</tr>
$tz
</table>"; 
$headers ="From:"._NAME_AD_."<".$ad_mail."> \r\n";
$headers .= "Reply-To:"._NAME_AD_."<".$ad_mail."> \r\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=utf-8\n";

mail($to,$sub,$body,$headers);	
	
}




Tag : PHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-09-17 11:01:14 By : iaunz View : 1127 Reply : 3
 

 

No. 1

Guest


Code (PHP)
function send_out($email,$uid,$pid) // Mail แจ้งข้อมูลลืมรหัสผ่าน
{	
	$userdt=getUserById($uid);	
		
	$ad_mail = admin_email();
	$to=$email;
	$rec=mysql_fetch_array(mysql_query("select forget_mail from admin_mail"));
	$sub=_MOMS_TEAM_." - "._SEND_OUT_;

$toz=mysql_query("select * from `order` where id='016700' limit 1");
if($ro=mysql_fetch_array($toz));
else {
	echo '<b>ไม่พบข้อมูลที่ต้องการ</b>';
	}
	
$tl=mysql_query("select * from orderlist where oid='016700' order by id");
$arr1=array();
$list=array();
while($x=mysql_fetch_array($tl))
	{
	$list[$x[id]]=$x;
	$arr1[$x[pid]]=$x[pid];
	}
$pids=implode(',', $arr1);

$plist=array();
if($pids!='')
	{
	$tp=mysql_query("select id,pcode,instock from product where id in ($pids)");
	while($x=mysql_fetch_array($tp))
		$plist[$x[id]]=$x;
	}

if($ro[uid]>0)
	{
	$td=mysql_query("select id,username from dealer where id='{$ro[uid]}' limit 1");
	if($rd=@mysql_fetch_assoc($td))
		{
		}
	}

$tm=mysql_query("select * from payment order by onum");

/*if($rd[username]!=''){ $l= '<th align='left'>Username </th><td align='left'>'.$rd[username].'</td>'; } else { '<th align='left'>พนักงานขาย </th><td align='left'>'.$ro[saleman].'</td>'; };*/
if($rd[username]!=''){ $l= '<tr><th align=\'left\'>Username </th><td align=\"left\">'.$rd[username].'</td></tr>'; } else { $l= '<tr><th align=\"left\">พนักงานขาย </th><td align=\"left\">'.$ro[saleman].'</td></tr>'; };

$totalprice=0;
 
foreach($list as $x){
	$sumprice=$x[qty]*$x[price];
	$totalprice+=$sumprice;
	$ll.= "<tr><td width='150' align='center'>".$plist[$x[pid]][pcode]."</td><td width='400' align='center'>".$x[name]."</td><td width='80' align='center'>".number_format($x[price],2)."</td><td width='80' align='center'>".$x[qty]."</td><td width='80' align='center'>".number_format($sumprice,2)."</td></tr><br />";
	}


	$body="<table width='100%'>
	<tr valign='top'>
		<td>
			<div style='font-size:18pt; font-weight:bold;'>
				CYBERBATT
			</div>
			<div style='font-size:18pt; font-weight:bold;'>
				ใบสั่งซื้อ
			</div>
		</td>
		<td align='right'>
			<table style='font-size:12pt;'>
				<tr><th align='left'>ใบสั่งสินค้าเลขที่</th><td align='left'><b>016700</b></td></tr>
				<tr><th align='left'>ผู้สั่งซื้อ </th><td align='left'>$ro[name]</td></tr>
				$l
			</table>
		</td>
	</tr>
</table>
<table cellspacing='0' cellpadding='2' class='sptb1' >
<tr bgcolor='#66CC99'>
	<th>รหัสสินค้า</th>
	<th>ชื่อสินค้า</th>
	<th align='center'>ราคา/หน่วย</th>
	<th align='center'>จำนวน</th>
	<th align='center'>ราคารวม</th>
</tr>
$ll</table>"; 

$headers ="From:"._NAME_AD_."<".$ad_mail."> \r\n";
$headers .= "Reply-To:"._NAME_AD_."<".$ad_mail."> \r\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=utf-8\n";

mail($to,$sub,$body,$headers);	
	
}


ได้แล้วครับ พอดีลืมเติมจุดตรง $ll.=






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-09-17 12:17:01 By : iaunz
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Go to : php กับ mysql จะส่งอีเมล์ให้สมาชิกในฐานข้อมูล โดยข้อมูลมีหลายพัน record ได้ด้วยวิธีไหนบ้างครับ

#ref 1 ผมเขียนไว้ให้เป็นตัวอย่างครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-09-18 08:33:31 By : webmaster
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP Sending Email</title>
</head>
<body>
<?
	$strTo = "[email protected]";
	$strSubject = "Test Send Email";
	$strHeader = "Content-type: text/html; charset=windows-874\n"; // or UTF-8 //
	$strHeader .= "From: Mr.Weerachai Nukitram<[email protected]>\nReply-To: [email protected]";
	$strVar = "My Message";
	$strMessage = "
	<h1>My Message</h1><br>
	<table width='285' border='1'>
	 <tr>
	 <td><div align='center'><strong>My Message </strong></div></td>
	 <td><div align='center'><font color='red'>My Message</font></div></td>
	 <td><div align='center'><font size='2'>My Message</font></div></td>
	 </tr>
	 ";
	 $strSQL = "SELECT * FROM table-name";
	 $objQuery = mysql_query($strSQL);
	 while($objResult = mysql_fetch_array($objQuery))
	 {
	 $strMessage .= "<tr>
	 <td><div align='center'>".$objResult["item1"]."</div></td>
	 <td><div align='center'>".$objResult["item2"]."</div></td>
	 <td><div align='center'>".$objResult["item3"]."</div></td>
	 </tr>";
	 }

	$strMessage .= "</table>";

	$flgSend = @mail($strTo,$strSubject,$strMessage,$strHeader);  // @ = No Show Error //
	if($flgSend)
	{
		echo "Email Sending.";
	}
	else
	{
		echo "Email Can Not Send.";
	}
?>
</body>
</html>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-05 13:05:24 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามเรื่องการเขียน Function mail และ loop ข้อมูลออกมาเพื่อส่ง
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่