我正在使用PHP,我有一个简单的购物车,当您点击添加按钮时,它会添加项目。
所有内容都收集在名为$ cartOutput
的变量中当我回应它时,它会按预期给我购物车中的所有东西。与var_dump相同。一切都在那里
然而,当我尝试将其放入电子邮件并将其发送时。它切断了第一项。谁能想到为什么会这样呢?
在将其放入电子邮件之前,没有任何过滤器。它只是变量
中的内容这是一个例子......
// e.g of the php variable being assembled for each item
$cartOutput .= "<tr>";
$cartOutput .= "<td>" . $product_name . "</td>";
$cartOutput .= "<td>$" . $price . "</td>";
//通过电子邮件发送变量
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$company = $_POST['company'];
$name = $_POST['name'];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$commercialAdd = $_POST['commercial'];
$residentialAdd = $_POST['residential'];
$city = $_POST['city'];
$province = $_POST['province'];
$postal_code = $_POST['postal_code'];
$email = $_POST['email'];
$special_instructions = $_POST['special_instructions'];
$date = date("Y/m/d");
$time = date("h:i:sa");
$to = "xxx@gmail.com";
$header = "Cc:xxx@somedomain.com \r\n";
$subject = "Email Order - $company ($date - $time)";
$message = <<<EOD
<h1>Email Order - $date - $time </h1>
<h3><strong><u>Company:</u></strong> $company</h3>
<h3><strong><u>Name:</u></strong> $Name </h3>
<h3><strong><u>Address:</u></strong> $address<br>
$address2</h3>
<h3><strong><u>Residential:</u></strong> $commercialAdd </h3>
<h3><strong><u>Commercial:</u></strong> $residentialAdd </h3>
<h3><strong><u>City:</u></strong> $city</h3>
<h3><strong><u>Province:</u></strong> $province</h3>
<h3><strong><u>Postal Code:</u></strong> $postal_code</h3>
<h3><strong><u>Phone Number:</u></strong> $phone</h3>
<h3><strong><u>Email:</u></strong> $email</h3>
<h3><strong><u>Special Instructions:</u></strong> $special_instructions</h3>
<table>
<thead>
<tr>
<th>Item</th>
<th>Price</th>
<th>Weight (Kg)</th>
<th>Qty</th>
<th>Subtotal</th>
<th></th>
</tr>
</thead>
<tbody>
$cartOutput
<tr>
<td class="totals"><strong>Total</strong></td>
<td class="totals"> </td>
<td class="totals">$weightTotal kg</td>
<td class="totals">$quantityTotal</td>
<td class="totals">$ $cartTotal</td>
<td class="totals"> </td>
<tr>
</tbody>
</table>
EOD;
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
header("location: complete.php");
exit();
}
else {
echo "Order could not be sent. Please try again or contact our office for assistance";
}
}
答案 0 :(得分:0)
可能您遇到了电子邮件格式问题。 mail()
要求正文结束\ r \ n中的每一行,每行少于70个字符。您需要对HTML进行编码或将其作为附件包含在内。有关示例,请参阅this set of instructions。