【问题标题】:PEAR Mail function - Problems with line breaksPEAR Mail 功能 - 换行问题
【发布时间】:2013-09-19 13:21:58
【问题描述】:

我正在尝试发送带有附件的简单纯文本电子邮件。到目前为止,除了正确插入换行符之外,一切都运行良好。代码:

$text = 'Product Name: '.$exchange;
    $text .= '\nCompany Name: '.$company_name;
    $text .= '\nContact Name: '.$contact_name;
    $text .= '\nContact Email: '.$contact_email;
    $text .= '\nWebsite: '.$website;
    $text .= '\nDescription: '.$description;


$subject =  "I'm interested in signing up.";

$visitor_email = 'blah@blah.com';

$crlf = "\n";

$message = new Mail_mime($crlf);

$message->setTXTBody($text);

$message->addAttachment($path_of_uploaded_file);

$body = $message->get();

$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$visitor_email);

$headers = $message->headers($extraheaders);

$mail = Mail::factory("mail");

$mail->send('blah@blah.com', $headers, $body);

 if (PEAR::isError($mail)) {
    echo($mail->getMessage());
}
else {
    echo("Your request has been submitted successfully. Thanks!");
    header("Location: home.html");
    die();
}

} else {
  // submitNoLogo();
    echo 'not sent';
}

在电子邮件中,所有文本都在一行中,\n 在我想要的行之间。有谁知道可能会发生什么?谢谢。

【问题讨论】:

    标签: php pear


    【解决方案1】:

    将您的 $text 放在双引号而不是单引号中

     <?php
         $text = 'Product Name: '.$exchange;
         $text .= "\nCompany Name: ".$company_name;
         ....
    

    【讨论】:

      【解决方案2】:

      你应该把\r\n不只是/n,也把它们放在最后而不是开始

      $text .= 'Company Name: '.$company_name.'\r\n';
      $text .= 'Contact Name: '.$contact_name.'\r\n';
      $text .= 'Contact Email: '.$contact_email.'\r\n';
      $text .= 'Website: '.$website.'\r\n';
      $text .= 'Description: '.$description.'\r\n';
      

      \r\n 是 Windows 系统的行尾字符,\n 是 UNIX 系统的行尾字符。

      【讨论】:

      • 这在您使用 '\r\n' btw 之前将不起作用......您也可以使用 EOL
      猜你喜欢
      • 2013-04-02
      • 2013-07-07
      • 2012-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-27
      • 2021-12-31
      • 2011-06-24
      相关资源
      最近更新 更多