我尝试了“\n”和PHP_EOL,但都不起作用。 我收到$_post['message'],需要在发送之前向其中添加更多信息,并用换行符分隔。
if(isset($_POST['submit'])) {
$name = $_POST['full-name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mailTo = 'mail@example.com';
$subject = 'Message from ' . $name;
$headers = array(
'From' => $email,
'Reply-To' => $email,
'Content-Type' => 'text/html; charset=UTF-8'
);
$message = $message . PHP_EOL . "E-mail from: " . $email . PHP_EOL . "Name: " . $name;
mail($mailTo, $subject, $message, $headers);
}
你会怎么做?
根据W3Schools:
Windows注意:如果在消息中的行首发现句号,则可能将其删除。 要解决这个问题,用双点代替句号:
<?php
$txt = str_replace("\n.", "\n..", $txt);
?>
https://www.w3schools.com/php/func_mail_mail.asp
您还可以尝试使用
将邮件格式化为html