尝试从表单发送样式的电子邮件

时间:2013-10-01 12:32:16

标签: php html email

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

$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标签的电子邮件收件箱中显示相同。如何以这种方式设置电子邮件正文。谢谢

1 个答案:

答案 0 :(得分:2)

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

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

那就是它!