PEAR邮件功能 - 换行问题

时间:2013-09-19 13:21:58

标签: php pear

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

$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 \ n介于我想要的行之间。有人知道可能会发生什么吗?谢谢。

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

你应该把 \ 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系统的行尾字符。