我正在尝试发送一封带有附件的简单纯文本电子邮件。到目前为止,除了正确插入换行符之外,一切都运行良好。法典:
$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';
}
在电子邮件中,所有文本都在一行上,' 在我想要的行之间。有谁知道会发生什么?谢谢。
将$text放在双引号而不是单引号中
<?php
$text = 'Product Name: '.$exchange;
$text .= "'nCompany Name: ".$company_name;
....
你应该把 ''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' 是 Windows 系统的行尾字符,' 是 UNIX 系统的行尾字符。