通过PHP mail()函数发送的HTML在邮件

时间:2018-05-03 15:43:50

标签: php html phpmailer html-email

我在mail()设置了PHP功能非常简单:

$to = $_POST['address_to_send'];
$subject = "New Message";
$message = $_POST['content_to_send'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: me@example.com" . "\r\n";

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

echo完全以我想要的方式显示我可爱的格式HTML,并按预期将电子邮件发送到正确的主题和正确的地址。

但是,电子邮件的实际内容是空白的???

使用PHP生成内容但不认为这会产生影响,因为echo只显示正确格式化的HTML。

对此有任何帮助或建议将不胜感激。

/ --------- --------- EDIT \

好的,所以在测试后echo仅在WAMP上本地工作,而不是在我的服务器上。

尝试使用var_dump()来尝试弄清楚发生了什么,虽然在WAMP中它给了我字符串,当它在服务器上时它是空的。

所以我认为这与我如何解雇邮件功能有关。

我有一个这样的表单(在PHP中生成):

<form action='purchase_orders.php?id=$order_id' method='POST'>
<button onclick='send_po($i)'>Send to $email</button><br />
<input type='hidden' id='po_content_to_send' name='po_content_to_send'>
<input type='hidden' id='po_address_to_send' name='po_address_to_send' value='$email'>
</form>

这会在JS中触发以下函数:

function send_po(po){
    var po_to_send = document.getElementById('purchase_order_'+po).innerHTML;
    document.getElementById('po_content_to_send').value = po_to_send;
    this.form.submit();
}

这会在提交表单之前将相关DIV的内容添加到隐藏的输入中,该表单应触发此PHP

if(isset($_POST['po_content_to_send']) && isset($_POST['po_address_to_send'])){
    $to = $_POST['po_address_to_send'];
    $subject = "New Purchase Order";
    $message = $_POST['po_content_to_send'];
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= "From: me@example.com" . "\r\n";
    var_dump($message);
    //mail($to,$subject,$message,$headers);
}

1 个答案:

答案 0 :(得分:0)

我需要<link href="https://fonts.googleapis.com/css?family=Francois+One" rel="stylesheet"> <div class="background"></div> <div class="input"></div> <div class="typing"> <div class="input-group"> <div class="form-group"> <label for="text">Please Type Here:</label> <input type="text" class="form-control" id="input"> </div> </div> </div> <div class="output" id="output"> </div>在我的按钮上提交,然后void f(X &src, Y &dest) { ... // do processing based on "src" #pragma omp parallel for for (...) { } ...// put output into "dest" } int main() { ... for(...) { // It is impossible to make this loop processing parallel one. f(...); } ... return 0; } 才能填充该值。