|
 |
|
สอบถามปัญหาเรื่องการ insert ข้อมูล พอดีทำระบบกล่องข้อความสมาชิก แล้วติดปัญหา ? |
|
 |
|
|
 |
 |
|
ใช้ for วนลูปดึงข้อมูลสมาชิกทั้งหมดแล้วทำการส่งครับ
|
 |
 |
 |
 |
Date :
2012-03-02 07:53:54 |
By :
narubet |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
$username = "xxxxx";
$password = "xxxxx1234";
$hostname = "localhost";
$dbconn = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$database = mysql_select_db("bsmartprint",$dbconn);
$query = "SELECT customers_email_address FROM customers";
$result = mysql_query($query) or die(mysql_error());
$data = mysql_fetch_assoc($result);
$entry = mysql_num_rows($result);
//Check if entry exists
if($entry !== 0){
$to = "customers_email_address";
// $to = "[email protected]";
$message = "123456789";
$from = "B-Smart Center";
$Subject = "B-Smart";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-885n-l\n";
$headers .= "From: $from\n";
if(mail($to, $from, $subject, $message, $headers)){
echo 'Email sent';
}else{
echo 'Failed sending email';
}
}else{
echo 'No email entry found';
}
mysql_close($dbconn);
?>
|
 |
 |
 |
 |
Date :
2012-03-02 09:00:37 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตามตัวอย่างครับ แนบ Database มาให้ด้วยครับ
Code
CREATE TABLE `customer` (
`CustomerID` varchar(4) NOT NULL,
`Name` varchar(50) NOT NULL,
`Email` varchar(50) NOT NULL,
`CountryCode` varchar(2) NOT NULL,
`Budget` double NOT NULL,
`Used` double NOT NULL,
PRIMARY KEY (`CustomerID`)
) ENGINE=MyISAM;
INSERT INTO `customer` VALUES ('C001', 'Win Weerachai', '[email protected]', 'TH', 1000000, 600000);
INSERT INTO `customer` VALUES ('C002', 'John Smith', '[email protected]', 'EN', 2000000, 800000);
INSERT INTO `customer` VALUES ('C003', 'Jame Born', '[email protected]', 'US', 3000000, 600000);
INSERT INTO `customer` VALUES ('C004', 'Chalee Angel', '[email protected]', 'US', 4000000, 100000);
Code (PHP)
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("customer");
$strSQL = "SELECT * FROM customer ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
$strTo = $objResult["Email"];
$strSubject = "Test Send Email";
$strHeader = "Content-type: text/html; charset=windows-874\n"; // or UTF-8 //
$strHeader .= "From: apinya \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>
<tr>
<td><div align='center'>My Message</div></td>
<td><div align='center'>My Message</div></td>
<td><div align='center'>My Message</div></td>
</tr>
<tr>
<td><div align='center'>".$strVar."</div></td>
<td><div align='center'>".$strVar."</div></td>
<td><div align='center'>".$strVar."</div></td>
</tr>
</table>";
@mail($strTo,$strSubject,$strMessage,$strHeader);
}
?>
|
 |
 |
 |
 |
Date :
2012-03-02 09:03:22 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอโทษครับพี่ มันไม่ใช่ email อะครับ เป็นกล่องข้อความในเว็บไซต์ิอะครับ
|
 |
 |
 |
 |
Date :
2012-03-02 09:57:41 |
By :
จอห์นเชียร์โฮสติ้ง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
..?..
|
 |
 |
 |
 |
Date :
2012-03-02 11:42:44 |
By :
วีรวัฒน์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|