php从变量中解析新行

时间:2017-06-03 06:16:01

标签: php email line

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

在emailmessages.csv中

会读到

"from","to","subject","message"
"from@example.com","to@example.com","the subject","message is this new line \r\n 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" . "\r\n";
    $headers .= "Content-type: text/plain; charset=iso-8859-1" . "\r\n";
    $headers .= "From: $from" . "\r\n";
    mail($to, $subject, $message, $headers);
}

explode命令可以帮助我(爆炸$ message?)

2 个答案:

答案 0 :(得分:0)

电子邮件大部分时间呈现为HTML,因此请使用<br/>代替\r\n

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

答案 1 :(得分:0)

我找到了答案

$message = str_replace('\r\n', "\r\n", $message);