我有以下php代码
$sql = "SELECT * FROM Requests ORDER BY RequestID DESC LIMIT 1";
$result = $conn->query($sql);
while ($row1 = $result->fetch_assoc()){
echo "Name: " . $row1['FirstName'] . " " . $row1['LastName'];
echo "<br> Date Needed: " . $row1['DateNeeded'];
echo "<br> Company: " . $row1['Company'] . "<br> Account: " . $row1['Account'] . "<br> Brand: " . $row1['Brand'] . "<br> Wants: ";
$requestID = $row1['RequestID'];
$sql = "SELECT * FROM ItemsPerRequest, Items WHERE Items.ItemID = ItemsPerRequest.ItemID AND RequestID = '$requestID'";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
echo $row ['Quantity'] . " ";
echo $row['ItemDescription'];
if ($row['Quantity'] > 1) {
echo "s";
}
echo " <br> ";
}
echo "Comments: " . $row1['Comments'];
echo "<br> File Name: " . $row1['FileLink'];
$file = $row1['FileLink'];
}
哪个很漂亮,并给我这个输出例如
姓名:Sharkn8do
所需日期:2016-12-28
公司:饮料
帐户:布法罗酒吧
品牌:盛大
想要:4个传单 - 大11&#34; x17&#34; s
18桌帐篷 - 框架样式
评论:现在关于大峡谷咖啡豆粗壮的草案
文件名:2016-12-08-000000015-Me.jpg
现在,我希望在电子邮件正文中输出。我尝试将其复制并粘贴到
$message = "Form submission";
我的mail()代码的一部分......但那确实没有用。我想要的只是代码中的echo部分。但!因为Wants:(4个传单,18个桌子帐篷)部分是基于数组生成的,我无法真正分配变量并将主题发送给那个,对吧?
这是邮件代码:
$to = "test@email.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = "Form submission";
$message = //WHAT DO;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
没有PHPMailer或类似的建议。我试过了,不喜欢它,不起作用......所以请将mail()放在首位。
答案 0 :(得分:1)
创建一个名为$output='';
的变量,而不是echo',并用$output .= [text to be echo'ed here];
替换每个回声。这将创建一个带有回声的字符串。然后,您可以在结尾处回显显示的值或将其添加到电子邮件中。
例如:
$output = "";
//just a simple loop
for($i=0; $i<10; $i++){
//basically what you have echo'ing a string in a loop.
//echo "The loop is on number: {$i}\n";
//what you should do with concatenation
$output .= "The loop is on number: {$i}\n";
}
//now you have a variable with the same text that
//would have been echo'ed. You can echo it here to
//get the same output or use it somewhere else.
echo $output;
//or email it
mail($to, $subject, "This is the output: {$output}", $headers);