[英]how to format message body of email?
i have developed a simple php contact form, that's working fine, but i am unable to format the body of the message as per my requirement, my code is given below, i am getting mail in a single line format, 我已经开发了一个简单的php联系人表格,可以正常工作,但是我无法按照我的要求格式化邮件的正文,下面给出了我的代码,我收到的邮件格式为单行,
where i want every information on a new line like this 我想要这样的新行中的所有信息
"Name: Syed Sheeraz Ahmed “名称:Syed Sheeraz Ahmed
Contact No: 03453594552 联络号码:03453594552
Email: abc@abc.com 电子邮件:abc@abc.com
Address: R-47, Sector 9, North city. 地址:北市9区R-47。
Requirement: hello how are you" 要求:你好,你好吗?
<?php
$to = "sheery_1@hotmail.com";
$subject = "From Website Contact Form";
$name = $_REQUEST['name'] ;
$contact = $_REQUEST['contact'] ;
$address = $_REQUEST['address'] ;
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";
$MESSAGE_BODY .= "Contact No: ".$_POST["contact"]."<br>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY .= "Address: ".$_POST["address"]."<br>";
$MESSAGE_BODY .= "Requirement: ".nl2br($_POST["message"])."<br>";
$message = $_REQUEST['message' + 'address' + 'contact'] ;
$from = $_REQUEST['email'] ;
$headers = "From:" . $from;
mail($to,$subject,$MESSAGE_BODY,$headers);
echo "Mail Sent.";
?>
您想要换行( \\n
)而不是HTML换行符( <br>
),因为您的电子邮件未标记为具有HTML正文(并且具有HTML正文的电子邮件实际上应该具有包含纯文本和HTML的多部分MIME正文自“仅HTML”以来的版本是垃圾邮件检测器的不错的标记)。
As you are using html tag in your email content. 当您在电子邮件内容中使用html标签时。
Set the content- type
text/html
in the header of your mail 在邮件标题中设置content- type
text/html
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
OR 要么
you can save yourself from this type of problems using phpmailer 您可以使用phpmailer避免此类问题
If your email is sending as text then the 如果您的电子邮件以文本形式发送,则
tags will do nothing. 标签将无济于事。 Try using a new line character for example: 例如,尝试使用换行符:
$MESSAGE_BODY = "Name: ".$_POST["name"]."\\n"; $ MESSAGE_BODY =“名称:”。$ _ POST [“名称”]。“ \\ n”;
That should sort your problem. 那应该解决您的问题。
in above example <br>
is printed after the variable printed, why? 在上面的示例中, <br>
在变量打印之后被打印,为什么? how to remove <br>
for example: 如何删除<br>
例如:
$_Post["name"]
has value "jhon". $_Post["name"]
值为“ $_Post["name"]
”。
it prints: jhon<br>
它打印: jhon<br>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.