简体   繁体   English

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

[英]Trying to send a styled email from a form

I am trying to send a email from a form.I wanna style email body.I have store all field values in different variables and calling them in another variable to collect and send to email which i have set to receive emails. 我正在尝试从表单发送电子邮件。我想要设置电子邮件正文。我将所有字段值存储在不同的变量中并在另一个变量中调用它们以收集并发送到我已设置为接收电子邮件的电子邮件。 My code is for collecting field values, 我的代码用于收集字段值,

$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;

if i put html tags around the variable for example 如果我在变量周围放置html标签,例如

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

inside variable 内部变量

$body = "";

it display same in the email inbox with html tags.How i have to style email body this way.Thanks 它在带有html标签的电子邮件收件箱中显示相同。如何以这种方式设置电子邮件正文。谢谢

You need to insert Content-type: header to your headers, like: 您需要在标题中插入Content-type:标题,例如:

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

and that's it! 就是这样!

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

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