以下代码旨在在销售完成后发送电子邮件。电子邮件的正文包含客户姓名,电子邮件地址等信息。我想做的是在电子邮件的最终输出中为每个字段添加换行符。我尝试过一个简单的HTML换行符和/ n和/ r哪个不起作用....任何想法?谢谢!
<?php
//Enter email to receive purchase alerts
///////////////////////////////////////////
$alert_email = 'sales@my-domain.com';
///////////////////////////////////////////
$username = $_POST['username'];
$password = $_POST['password'];
$to = $alert_email;
$subject = 'Sale! = ' .$course;
$message = $name. ' '. $email. ' '. $username. ' '. $password;
$headers = 'From: sales@my-domain.com' . "\r\n" .
'Reply-To: hi@my-domain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
需要更改的行我确定是这一行(并在此处插入换行符:
$message = $name. ' '. $email. ' '. $username. ' '. $password;
谢谢!
答案 0 :(得分:0)
通过应用标题Content-type:text/html
$to = $alert_email;
$subject = 'Sale! = ' .$course;
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <sales@my-domain.com>' . "\r\n";
$headers .= 'Reply-To: hi@my-domain.com' . "\r\n";
$message = $name. '<br /> '. $email. '<br /> '. $username. '<br /> '. $password;
mail($to, $subject, $message, $headers);
答案 1 :(得分:0)
\ n应该有效。请务必使用\而不是正斜杠。