-3
我正在工作的網站上有一個表單,用戶數據放在一個csv文件中,並存儲在我們的服務器上;後面跟着一封電子郵件,通知我附帶有csv文件的服務器上有一個新文件。PHP代碼輸出文件,但不發送確認郵件
但是最近表單停止發送確認電子郵件,雖然它仍然在服務器上創建文件。
這是代碼:
<?php
$fileDir = "csv/";
?>
<?php
if (isset($_POST['Submit'])) {
?>
<?php
$filename = date("ymd_His", time()) . ".csv";
$myFile = $fileDir . $filename;
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "TYPE,NAME,NUMBER,SIZE,BACKSTAMP,DESCRIPTION\n";
fwrite($fh, $stringData);
if ($_POST['qty_Royal_Doulton_Figurines'] > 0) {
for ($counter = 1; $counter <= $_POST['qty_Royal_Doulton_Figurines']; $counter += 1) {
$stringData = "Royal Doulton Figurine," . $_POST['name_Royal_Doulton_Figurines_' . $counter] . "," . $_POST['number_Royal_Doulton_Figurines_' . $counter] . "\n";
fwrite($fh, $stringData);
}
}
if ($_POST['qty_Royal_Doulton_Jugs'] > 0) {
for ($counter = 1; $counter <= $_POST['qty_Royal_Doulton_Jugs']; $counter += 1) {
$stringData = "Royal Doulton Jugs," . $_POST['name_Royal_Doulton_Jugs_' . $counter] . "," . $_POST['number_Royal_Doulton_Jugs_' . $counter] . "," . $_POST['size_Royal_Doulton_Jugs_' . $counter] . "\n";
fwrite($fh, $stringData);
}
}
if ($_POST['qty_Royal_Doulton_Bunnykins'] > 0) {
for ($counter = 1; $counter <= $_POST['qty_Royal_Doulton_Bunnykins']; $counter += 1) {
$stringData = "Royal Doulton Bunnykins," . $_POST['name_Royal_Doulton_Bunnykins_' . $counter] . "," . $_POST['number_Royal_Doulton_Bunnykins_' . $counter] . "\n";
fwrite($fh, $stringData);
}
}
if ($_POST['qty_Royal_Doulton_Beatrix_Potter'] > 0) {
for ($counter = 1; $counter <= $_POST['qty_Royal_Doulton_Beatrix_Potter']; $counter += 1) {
$stringData = "Royal Doulton Beatrix Potter," . $_POST['name_Royal_Doulton_Beatrix_Potter_' . $counter] . "," . $_POST['number_Royal_Doulton_Beatrix_Potter_' . $counter] . ",," . $_POST['backstamp_Royal_Doulton_Beatrix_Potter_' . $counter] . "\n";
fwrite($fh, $stringData);
}
}
if ($_POST['qty_Other_Royal_Doulton_Pieces'] > 0) {
for ($counter = 1; $counter <= $_POST['qty_Other_Royal_Doulton_Pieces']; $counter += 1) {
$stringData = "Other Royal Doulton Pieces," . $_POST['name_Other_Royal_Doulton_Pieces_' . $counter] . "," . $_POST['number_Other_Royal_Doulton_Pieces_' . $counter] . ",,," . $_POST['desc_Other_Royal_Doulton_Pieces_' . $counter] . "\n";
fwrite($fh, $stringData);
}
}
fclose($fh);
?>
<?php
}
?>
<?php
//define the receiver of the email
$to = '[email protected]';
//define the subject of the email
$subject = 'COLLECTION FOR SALE';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$message = $_POST['First_Name'] . $_POST['Last_Name'] . "\n" . $_POST['Address1'] . $_POST['Address2'] . "\n" . $_POST['City'] . ", " . $_POST['State'] . " " . $_POST['Zip'] . "\n" . $_POST['Country'] . "\n" . "Phone: " . $_POST['Phone'] . "\n" . "Fax: " . $_POST['Fax'] . "\n" . $_POST['Email'] . "\n--------------------\n" . $_POST['Comments'];
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: " . $_POST['Email'] . "\r\nReply-To: " . $_POST['Email'];
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-" . $random_hash . "\"";
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/csv/" . $filename)));
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-mixed-<?php
echo $random_hash;
?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php
echo $random_hash;
?>"
--PHP-alt-<?php
echo $random_hash;
?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
COLLECTION FOR SALE
--PHP-alt-<?php
echo $random_hash;
?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<font face="arial">
<strong><?php
echo $_POST['First_Name'];
?> <?php
echo $_POST['Last_Name'];
?></strong><br />
<?php
echo $_POST['Address1'];
?> <?php
echo $_POST['Address2'];
?><br />
<?php
echo $_POST['City'];
?>, <?php
echo $_POST['State'];
?> <?php
echo $_POST['Zip'];
?><br />
<?php
echo $_POST['Country'];
?><br />
Phone: <?php
echo $_POST['Phone'];
?><br />
Fax: <?php
echo $_POST['Fax'];
?><br />
<?php
echo $_POST['Email'];
?><br /><br />
<?php
echo $_POST['Comments'];
?>
</font>
--PHP-alt-<?php
echo $random_hash;
?>--
--PHP-mixed-<?php
echo $random_hash;
?>
Content-Type: text/csv; name="<?php
echo $filename;
?>"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
<?php
echo $attachment;
?>
--PHP-mixed-<?php
echo $random_hash;
?>--
<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail($to, $subject, $message, $headers);
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
<style type="text/css">
<!--
body,td {
font-family: Arial, Helvetica, sans-serif;
color: #333333;
font-size: 12px;
}
input,select,textarea {
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
color: #333333;
}
-->
</style>
<meta http-equiv="Refresh" content="3;URL=http://www.seawaychina.com" />
<br>
<table width="500" border="1" align="center" cellpadding="5" cellspacing="5">
<tr>
<td align="center"><img src="images/header.gif" /> </td>
</tr>
<tr>
<td align="center"><p> </p>
<p>Thank you, your list has been submitted!</p>
<p><font color="#FF0000"><i>Please note that it may take up to a month for us to process your list. Thank you for your patience!</i></font> <br />
</p>
<p><br />
</p></td>
</tr>
</table>
及以下的鏈接形式:
http://www.seawaychina.com/sellerform.aspx
請你幫助我嗎?
歡迎來到stackoverflow - 你會發現你得到更多的回答這樣的問題,如果你表明你試圖幫助自己。沒有人想讀一個巨大的劇本,其中大部分都是無關緊要的。我建議寫一個非常簡單的測試腳本,它只是調用mail()。如果這不起作用,那麼你知道這不是你的邏輯,它是底層系統,然後你可以轉向你的服務器日誌等。 –