douxing5598 2013-07-03 23:19
浏览 23
已采纳

如何自定义从php mail()脚本发送的电子邮件的方式

So I can't seem to word the question right - but I would like to know how would you go about changing the way this

$Body = "";
$Body .=   "Name: ";  
$Body .= $Name;
$Body .= "
";
$Body .= "City: ";
$Body .= $City;
$Body .= "
";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "
";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "
";

looks when it reaches my e-mail. When I receive the e-mail (using it as a contact form), I get this ->

Name: lloan
City: SomeCity
Email: some@email.com
Message: Testing

I tried <strong> $Body .= "Name: ";</strong> and that didn't work - I also tried it as $Body .= "<strong> Name: </strong>"; and again, nothing. Can anyone point me in the right direction? I really want to learn how to do this - I've googled it a couple of times, but I think it's the way I'm wording my question that's not helping me.

EDIT: So I'm able to do this now - $Body .= "<strong>Name: </strong>"; using the suggestions below of adding the headers and then adding that to the mail() function - however, how do I go about using it on a bigger scale? For example - What if I want to have a colored background or what not - Am I also able to use CSS in this kind of situation? The other questions on SO do not answer this in it's entirety.

  • 写回答

3条回答 默认 最新

  • doulvyi2172 2013-07-03 23:26
    关注

    Here's how:

    $to = 'yourmailtarget@example.com';
    
    $subject = 'Your email subject';
    
    $headers = "From: abc@abc.com 
    ";
    $headers .= "Reply-To: no-reply@abc.com 
    ";
    $headers .= "CC: abc@abc.com
    ";
    $headers .= "MIME-Version: 1.0
    ";
    $headers .= "Content-Type: text/html; charset=UTF-8
    ";
    
    $message = 'Put your html message here<br>';
    $message .= "<b>HTML feature is now enabled</b><br>";
    $message .= "<table border="1"><tr><td>Hello</td><td>World</td></tr></table>";
    $message .= "For the styling, you can use inline styling:<Br>";
    $message .= "<span style='color:#FF0000;'>This is red color</span>";
    mail($to,$subject,$message,$headers,$parameters);
    

    The most important part to answer your question is this line:

    $headers .= "Content-Type: text/html; charset=UTF-8
    ";
    

    That tells the system to produce the email using the HTML format.

    Hope this helps

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么