gpt4 book ai didi

php - PHP 中的断行不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:02:51 24 4
gpt4 key购买 nike

我正在尝试使用换行符来格式化电子邮件,所以它看起来像:

Name:
Email:
Message:

我添加了 \r\n 但它什么也没做,然后我尝试添加了 $headers .= 'Content-type: text/html;字符集=utf-8'。 "\r\n"; 认为我需要告诉它这是 HTML 而它什么也没做。

我做错了什么?

<?php
session_start();

if ($_SERVER['REQUEST_METHOD'] == 'POST'){
ob_start();

if(isset($_POST['name'])
&& isset($_POST['email'])
&& isset($_POST['message'])
&& isset($_POST['token'])){

if($_SESSION['token'] != $_POST['token']){
$response = "0";
} else {
$_SESSION['token'] = "";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$to = "support@loaidesign.co.uk";
$subject = "New Message From: $name";
$message = "Name: $name\r\n
Email: $email\r\n\r\n
Message: $message";

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: '.$email . "\r\n";
$mailed = ( mail($to, $subject, $message, $headers) );

if( isset($_POST['ajax']))$response = ($mailed) ? "1" :
"0"; else $response = ($mailed) ? "<h2>Success!</h2>" :
"<h2>Error! There was a problem with sending.</h2>";
echo $response;
}

} else {
echo "Form data error!";
}

ob_flush();
die();
}

?>

最佳答案

你应该试试 <br/> HTML 标签,因为您指定了 text/html内容类型:

$message = "Name: $name<br/>
Email: $email<br/><br/>
Message: $message";

关于php - PHP 中的断行不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21560059/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com