无法在电子邮件中插入换行符

时间:2013-02-17 16:26:14

标签: php email

我使用自己的send_mail函数,似乎无法将新行传递给它。

我尝试了double-quote-fix,但它似乎不起作用。调用我的函数时,这些新行可能会丢失吗?

功能:

abstract class util {
    ...
    static function send_email($to,$from,$subject,$message){
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'To: '.$to.'' . "\r\n";
        $headers .= 'From: '.$from.'' . "\r\n";
        mail($to, $subject, $message, $headers);        
    }
    ...
}
电话:

    $subject = "Your email activation for ". DOMAIN;
    $message = "Dear ".$this->name.", \r\n Welcome to ********. Click the link below to activate your account and get started. \r\n ".VERIFY_LINK."?code=".$this->code."&id=".$this->id;
    util::send_email($this->email, EMAIL_REGISTER, $subject, $message);

但电子邮件总是最终成为单行

任何想法?

2 个答案:

答案 0 :(得分:1)

使用$message = nl2br($message)函数将\ n转换为换行符,因为您的电子邮件是html。或者,您可以使用<br />标记代替\ n进行换行来编写邮件

答案 1 :(得分:1)

尝试使用<br/>代码而不是/ n?

相关问题