我想知道为什么partsname和qty不会在电子邮件正文中回显。
这是我的代码:
<?php
include('../config.php');
$roomid = $_POST['roomid'];
$status=$_POST['status'];
$tc=$_POST['transactioncode'];
mysql_query("UPDATE athan_orders SET status='$status' WHERE id='$roomid'");
header("location: viewords.php");
mysql_query("SELECT * FROM athan_members where id='$roomid'");
$recepient=$_POST['id'];
mysql_query("SELECT * FROM orderdetails where transactioncode = '$tc'");
$partsname=$_POST['partsname'];
$qty=$_POST['qty'];
$to = "$recepient"; //enter the recipients email address here
$subject = "Order Confirmed"; //email subject
$message = "
<html>
<head>
<title>Order Confirmed</title>
</head>
<body>
<p>Your Order at Athan Motorcycles has been confirmed by the admin. Please contact the company for the details and verification of your order.</p>
<table>
<tr >
<td><div> Products</div></td>
<td>Qty</td>
</tr>
</table>
<tr>
<td>"echo "$partsname"";
<td>"echo "$qty"";
</td>
</td>
</tr>
<table>
<tr>
<th>Thank you!</th>
<th>-Athan Motorcycles</th>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$fromemail = "melvin.napoles@yahoo.com"; //enter senders email address here
$headers .= "From: <". $fromemail . ">\r\n";
//$ccemail = ""; //cc email address
//$headers .= "Cc: $ccemail" . "\r\n";
if (mail($to,$subject,$message,$headers) == TRUE){
print "Success!";
}else{
print "Error!";
}
?>
所以我从订单详细信息中查询零件名称和数量,并为它们创建一个变量。然后我把它插入电子邮件表格。它是正确的还是调用变量有什么问题?
答案 0 :(得分:2)
不,它不正确,你不能在变量里面使用echo。用它来表示变量:
$message = "
<html>
<head>
<title>Order Confirmed</title>
</head>
<body>
<p>Your Order at Athan Motorcycles has been confirmed by the admin. Please contact the company for the details and verification of your order.</p>
<table>
<tr >
<td><div> Products</div></td>
<td>Qty</td>
</tr>
</table>
<tr>
<td>$partsname
<td>$qty
</td>
</td>
</tr>
<table>
<tr>
<th>Thank you!</th>
<th>-Athan Motorcycles</th>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
";
答案 1 :(得分:0)
连接字符串时,不使用echo命令;你用一段时间来连接它们。
此外,echo和print非常相似,但echo允许您输出多个字符串,而print只输出一个。因此,您应该将打印功能更改为回显,并且通常只使用echo而不是print。
但是,要修复字符串的连接,请更改以下行:
<td>"echo "$partsname"";
<td>"echo "$qty"";
对此:
<td>".$partsname."
<td>".$qty."