 |
PHP Sending Email Attachment files CSV ผมได้ทำตามบทเรียนทุกอย่าง สร้าง Deta Bese ตาม แต่ไม่สามารถส่ง Mail ได้ |
|
 |
|
|
 |
 |
|
ผมได้ทำตามบทเรียนทุกอย่าง สร้าง Deta Bese ตาม แต่ไม่สามารถส่ง Mail ได้ โชว์ Email Can Not Send ไม่ทราบว่าต้อง Set อะไรเพิ่มเติมอีกไหมครับ ต้องการส่งไปที่ Hotmail
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL To CSV</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
<div align="center"><br>
<input name="btnExport" type="button" value="Export" onClick="JavaScript:window.location='phpCSVMySQLExport.php';">
</div>
</body>
</html>
<html>
<head>
<title>ThaiCreate.Com PHP & Write CSV</title>
</head>
<body>
<?
$filName = "customer.csv";
$objWrite = fopen("customer.csv", "w");
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
fwrite($objWrite, "\"$objResult[CustomerID]\",\"$objResult[Name]\",\"$objResult[Email]\",");
fwrite($objWrite, "\"$objResult[CountryCode]\",\"$objResult[Budget]\",\"$objResult[Used]\" \n");
}
fclose($objWrite);
//*************** Send Email ***************//
$strTo = "[email protected]";
$strSubject = "CSV Report";
$strMessage = "Download $filName for CSV Report";
//*** Uniqid Session ***//
$strSid = md5(uniqid(time()));
$strHeader = "";
$strHeader .= "From: Mr.Weerachai Nukitram<[email protected]>\nReply-To: [email protected]\n";
$strHeader .= "Cc: Mr.Surachai Sirisart<[email protected]>";
$strHeader .= "Bcc: [email protected]";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=windows-874\n"; // or UTF-8 //
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
$strContent1 = chunk_split(base64_encode(file_get_contents("$filName")));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$filName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$filName."\"\n\n";
$strHeader .= $strContent1."\n\n";
$flgSend = @mail($strTo,$strSubject,null,$strHeader); // @ = No Show Error //
if($flgSend)
{
echo "CSV Generated & Email Sending.";
}
else
{
echo "Email Can Not Send.";
}
?>
</table>
</body>
</html>
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2010-04-08 22:29:39 |
By :
jack |
View :
1265 |
Reply :
9 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Web Server ของท่านได้กำหนด SMTP : IP Address ของ Mail Server หรือยังครับ
|
 |
 |
 |
 |
Date :
2010-04-08 22:34:42 |
By :
panyapol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไว จริงๆ พี่วินนิ 
|
 |
 |
 |
 |
Date :
2010-04-08 22:35:11 |
By :
panyapol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วงนี้พี่ไม่ค่อยได้ตอบกระทู้เลยครับ งานเยอะจัด แต่ดีใจที่คนช่วยตอบกันเยอะจริง ๆ ครับ เยอะขึ้นทุกวัน ๆ
|
 |
 |
 |
 |
Date :
2010-04-08 23:06:35 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยบอกวิธี กำหนด SMTP : IP Address ของ Mail Server หน่อยครับ
ขอบคุณมากๆ
|
 |
 |
 |
 |
Date :
2010-04-09 04:53:37 |
By :
_่ฟแา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมเอา @ ออกแล้ว มันฟ้อง
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in
แล้วใน php.ini ต้อง Set อะไรบ้างครับ
ช่วยบอกวิธี กำหนด SMTP : IP Address ของ Mail Server หน่อยครับ ผมใช้ window7
อย่าพึ่งรำคาญนะครับ กำลังศึกษาตามบทเรียนของ Thaicreate.com อยากทำได้ ขอบคุณมากๆ
|
 |
 |
 |
 |
Date :
2010-04-09 05:07:39 |
By :
jack |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ windows 7 อยู่ครับ ใคร set เป็นช่วยที
|
 |
 |
 |
 |
Date :
2010-04-09 11:35:00 |
By :
jack |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองใช้บน Server จริง ๆ ครับ จะไม่ติดปัญหาเรื่องนี้เลยครับ
|
 |
 |
 |
 |
Date :
2010-04-09 12:14:58 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|