PHP解析了变量的新线



我的代码从逗号分隔的文件中读取行(电子邮件(并发送电子邮件。它运行良好,我将 r n 用于新行,但是当它发送邮件时,用户接收器 r n 而不是新行。

在emailmessages.csv中,它将阅读

"from","to","subject","message"
"from@example.com","to@example.com","the subject","message is this new line rn endline"

php:代码

$filename = "emailmessages.csv";
$csvArray = ImportCSV2Array($filename);
foreach ($csvArray as $row) {
    $to = $row['to'];
    $from = $row['from'];
    $subject = $row['subject'];
    $message = $row['message'];
    $headers  = "MIME-Version: 1.0" . "rn";
    $headers .= "Content-type: text/plain; charset=iso-8859-1" . "rn";
    $headers .= "From: $from" . "rn";
    mail($to, $subject, $message, $headers);
}

爆炸命令可以帮助我(爆炸$消息?(

我找到了答案

$message = str_replace('rn', "rn", $message);

在大多数情况下呈现为HTML的电子邮件,因此请使用<br/>代替rn

"from@example.com","to@example.com","the subject","message is this new line <br/> endline"

最新更新