[英]PHP - Email not sending as HTML. Why?
我可以使用php從我的聯系表發送純文本電子郵件,但不能將內容作為HTML發送。 以為我已經正確添加了標題,但顯然仍然存在問題。
這是我正在使用的腳本:
<?php
$to = 'test@hotmail.com';
$subject = 'From your Web';
$email = $_REQUEST['email'] ;
if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
//if "email" is filled out, send email
if (!trim($_REQUEST['name']) == "" )
{
if (!trim($_REQUEST['message']) == "" )
{
//send email
$name = $_REQUEST['name'] ;
$message = $_REQUEST['message'] ;
$mail = '
<html>
<body>
<table border=1>
<tr>
<td>Name:</td>
<td>'.$name.' </td>
</tr>
<tr>
<td>Email:</td>
<td>'.$email.'</td>
</tr>
<tr>
<td>Msg:</td>
<td>'.$message.'</td>
</tr>
</table>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $mail, "From:" . $email, $headers);
//mail($to, $subject, "From: " . $name . "/" . $email . " Msg: ".$message, "From:" . $email);
echo 'Thank you!';
}
else{
echo 'No empty msg';
}
}
else{
echo 'This is not a name';
}
}
else{
echo 'No correct email';
}
?>
嘗試這個。 代碼未經測試。 自從我用php編寫以來,它已經成為了無數的事物,因此我可以輕松地修改其中的一些語法。
$tacos = "crunchy";
$to = "tacos4eva@email.com";
$subject = "tacos";
$mail = "the tacos are $tacos today.";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: taco_master@email.com' . "\r\n";
$success = mail($to, $subject, $mail, $headers);
if ($success) echo "tacos were sent successfully";
else echo "tacos fell on the floor";
http://php.net/manual/zh/function.mail.php
從頁面上...
發送郵件時,郵件必須包含“發件人”標頭。 可以使用Additional_headers參數設置此參數,也可以在php.ini中設置默認值。
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.