0

我正在尝试从表单发送电子邮件。我想要设置电子邮件正文的样式。我将所有字段值存储在不同的变量中,并在另一个变量中调用它们以收集并发送到我设置为接收电子邮件的电子邮件。我的代码用于收集字段值,

$body = "
First Name: $name \n\n
Last Name: $LastName \n\n
Email: $email \n\n
Telephone: $Telephone \n\n
Country: $Country \n\n
City: $City \n\n
State: $State \n\n
Zip Code: $Zip \n\n
Address: $adress \n\n
";

//and here is code from where i am receiving emails which is working fine.

$headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;

例如,如果我在变量周围放置 html 标签

<div class="">Zip Code: $Zip </div>

内部变量

$body = "";

它在带有 html 标签的电子邮件收件箱中显示相同。我如何以这种方式设置电子邮件正文的样式。谢谢

4

1 回答 1

2

您需要在标题中插入Content-type:标题,例如:

$headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
$headers .= "\r\n" . 'Content-type: text/html';

就是这样!

于 2013-10-01T12:33:31.273 回答