简体   繁体   English

发送邮件消息的PHP

[英]sending mail message php

i just want to send the order content fetching the result in my database. 我只想发送订单内容,以在我的数据库中获取结果。 But when i echo it, it displays it on my php page. 但是,当我回显它时,它会在我的php页面上显示它。 i dont want it. 我不想要它。 I want the content to only appear in the email when the user receive it. 我希望内容仅在用户收到时才出现在电子邮件中。

This is my code. 这是我的代码。

while($row3 = mysqli_fetch_array($result3)){
$addresses=$row3['email'];
$to = $addresses;

$subject = "Order confirmed by Home and decor";



// message
$message = '


<html>
<body>
<table width="500" height="215" border="0">
<tr>
<th width="238" height="211" scope="col"><h1 align="left">Order # 1234</h1></p></th>
<th width="10" scope="col"></th>
<th width="243" scope="col"><p><img src="file:///D|/Programs/xampp/htdocs/images/sitelogo.PNG" width="224" height="68" align="right"></p></th>
</tr>
</table>

<table width="500" height="215" border="0">
<tr>
<th width="181" height="211" scope="col"><p align="left">Ship To:</p>
<p align="left"><?=$row3['first_name']?></p>
<p align="left"><?=$row3['address_1']?></p>
<p align="left"><?=$row3['city']?></p></th>
<th width="80" scope="col"></th>
<th width="40" scope="col"></th>
<th width="181" scope="col"><p align="left"></p>
<p align="right">Bill To:</p>
<p align="right"><?=$row3['first_name']?></p>
<p align="right"><?=$row3['address_1']?></p>
<p align="right"><?=$row3['city']?></p>
</th>
</tr>
</table>

<table width="500" height="94" border="0">
<tr>
<th height="43" scope="col"><div align="left">Order Date:</div></th>
<th scope="col">&nbsp;</th>
<th scope="col">&nbsp;</th>
<th scope="col"><div align="right">Shipping Method:</div></th>
</tr>
<tr>
<th width="126" height="43" scope="col"><div align="left">1/11/13</div></th>
<th width="433" scope="col">&nbsp;</th>
<th width="103" scope="col">&nbsp;</th>
<th width="156" scope="col"><div align="right">BEAST!</div></th>
</tr>
</table>
<table width="500" height="88" border="1">
<tr>
<th width="48" scope="col">Item</th>
<th width="264" scope="col">Product Name</th>
<th width="68" scope="col">Quantity</th>
<th width="92" scope="col">Price</th>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<hr>
<table width="500" height="227" border="0">
<tr>
<th height="43" scope="col">&nbsp;</th>
<th scope="col">&nbsp;</th>
<th scope="col">Subtotal:</th>
<th scope="col">&nbsp;</th>
</tr>
<tr>
<th height="43" scope="col">&nbsp;</th>
<th scope="col">&nbsp;</th>
<th scope="col">Tax:</th>
<th scope="col">&nbsp;</th>
</tr>
<tr>
<th height="43" scope="col">&nbsp;</th>
<th scope="col">&nbsp;</th>
<th scope="col">Shipping:</th>
<th scope="col">&nbsp;</th>
</tr>
<tr>
<th height="43" scope="col">&nbsp;</th>
<th scope="col">&nbsp;</th>
<th scope="col">Discount:</th>
<th scope="col">&nbsp;</th>
</tr>
<tr>
<th width="40" height="43" scope="col">&nbsp;</th>
<th width="278" scope="col">&nbsp;</th>
<th width="68" scope="col">Grand Total:</th>
<th width="96" scope="col">&nbsp;</th>
</tr>
</table>
<p align="right">&nbsp;</p>
</body>
</html>



';



// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";





$headers .= 'From: Order reminder <lol@gmail.com>' . "\r\n";



mail($to, $subject, $message, $headers);


}

Echo is when you want to call something out right. 回声是您想正确呼唤的地方。 I dont want it to echo, i just want to make the content appear in the email without echoing it. 我不希望它回显,我只想使内容出现在电子邮件中而不回显它。

Don't echo your variables, concatenate them into the string. 不要回显您的变量,将它们连接到字符串中。 ie

$message = "Some text ".$foo." some more text';

Not: 不:

$message = "Some text <?=$foo ?> some more text';

Check out this PHP Documentation for Turn on output buffering. 查阅此PHP文档中的“打开输出缓冲”。

http://php.net/manual/en/function.ob-start.php http://php.net/manual/zh/function.ob-start.php

Thanks 谢谢

what are the sally wrong shorttag doing right in the middle of your message content. 在您的邮件内容中间正确执行的简短标记是什么?

<?= ?>

see this post for more information about shorttags 请参阅此帖子以获取有关短标签的更多信息

I'd just replace all those things from 我会替换掉所有这些东西

<?php
    $message '...
        <p align="left"><?=$row3['first_name']?></p>

to

<?php
    $message '...
        <p align="left">'.$row3['first_name'].'</p>

You could use Heredoc syntax for this: 您可以为此使用Heredoc语法:

$message =<<<EOM
<html>
<body>
...
<table width="500" height="215" border="0">
<tr>
<th width="181" height="211" scope="col"><p align="left">Ship To:</p>
<p align="left">{$row3['first_name']}</p>
<p align="left">{$row3['address_1']}</p>
<p align="left">{$row3['city']}</p></th>
...
EOM;

It's recommended to apply htmlspecialchars() on $row3 first though: 建议尽管先在$row3上应用htmlspecialchars()

$row3 = array_map('htmlspecialchars', $row3);

This assumes you will not use $row3 later in your code 假设您稍后将不在代码中使用$row3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM