【问题标题】:Why is newline escape sequence not being converted into newline character?为什么换行符转义序列没有被转换为换行符?
【发布时间】:2011-02-15 05:08:58
【问题描述】:

我正在尝试使用 codeigniter 发送电子邮件,并且希望消息跨越多行。

$address = $this->input->post('email');
$subject = 'Please complete your registration';
$message = 'Thanks for registering! \n To complete your registration, please click on (or copy and paste in your browser) the following link: ' . base_url(). "users/confirmRegistration/" . $confirmation_code; //note the '\n' after thanks for registering

$this->load->library('email');
    $this->email->from('me@mysite.com', 'myname');
    $this->email->to($address); 
    $this->email->subject($subject);
    $this->email->message($message);    
    $this->email->send();

我希望邮件在“感谢注册”之后会出现换行符,但我得到了

感谢您的注册! n 完成您的注册(等等...)

我用\r\n试过了,结果几乎一样:

感谢您的注册! rn 完成(等等)。这就像应用了一个stripslash函数..

有什么想法吗?

【问题讨论】:

    标签: php email codeigniter escaping


    【解决方案1】:

    您需要以这种格式输入正文。 它工作正常。 拉胡尔

    $body = '亲爱的' 。 $row->fname 。 ' '。 $row->lname 。 ',' 。 '

    ' 。 “您在我们这里的帐户已被暂时禁用。” . '

    ' . “我们的辅导员关系团队会尽快与您联系。” . '

    ' . '您也可以通过 info@ggg.com 与我们联系' 。 '

    ' . '温暖的问候, ' 。 '

    ' . '团队';

    【讨论】:

      【解决方案2】:

      PHP 不会解析像 \n 这样的转义序列,包含在单引号内。

      您需要用双引号将您的消息字符串括起来。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-18
        • 1970-01-01
        • 1970-01-01
        • 2015-05-03
        • 1970-01-01
        • 1970-01-01
        • 2019-03-24
        • 1970-01-01
        相关资源
        最近更新 更多