0

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

$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 在我想要的行之间。有谁知道可能会发生什么?谢谢。

4

2 回答 2

1

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

 <?php
     $text = 'Product Name: '.$exchange;
     $text .= "\nCompany Name: ".$company_name;
     ....
于 2013-09-19T13:25:17.007 回答
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 系统的行尾字符。

于 2013-09-19T13:27:44.147 回答