我正在尝试将纯文本电子邮件发送给将要为我处理这些邮件的公司。我正在使用Swift Mailer库,据我所知 - 我没有问题。但我发送消息的公司表示,他们正在使用单行上的所有数据进入他们。当我使用此脚本向自己发送电子邮件时,它看起来很完美 - 每个数据都在一个单独的行上。
这是我正在使用的脚本。这很简单。
<?php
$to="";
$bcc="";
$subject = "Quote" ;
$domain = $_SERVER['HTTP_HOST'];
//Message
$message = "Domestic Quote Request\n";
$message .= "Full Name: $_POST[name]\n";
$message .= "Email: $_POST[email]\n";
$message .= "Phone: $_POST[phone]\n";
$message .= "Pickup Date: $_POST[shipdate]\n";
$message .= "Pickup City or Zip: $_POST[pickupzip]\n";
$message .= "Drop Off City or Zip: $_POST[dropoffzip]\n";
$message .= "Year: $_POST[vehicleyear]\n";
$message .= "Make: $_POST[vehiclemake]\n";
$message .= "Model: $_POST[vehiclemodel]\n";
$message .= "Carrier Type: $_POST[carriertype]\n";
$message .= "This Quote is from $domain";
require_once 'lib/swift_required.php';
// Create the Transport
// Mail
$transport = Swift_MailTransport::newInstance();
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create the message
$the_message = Swift_Message::newInstance()
// Give the message a subject
->setSubject($subject)
// Set the From address with an associative array
->setFrom($_POST['email'])
// Set the To addresses with an associative array
->setTo(array($to))
->setEncoder(Swift_Encoding::get8BitEncoding())
// Give it a body
->setBody($message, 'text/plain', 'us-ascii');
//Check is BCC Field is emtpy.
if ( !empty($bcc) )
{ //The BCC Field is not empty so set it.
$the_message->setBcc(explode(',', $bcc));
}
// Send the message
$result = $mailer->send($the_message);
}
header("location:index.php?s=1");
?>
以下是该公司所说的收到的一个例子:
Domestic Quote Request Full Name: Test Email: someone@somewhere.com Phone: 555-555-5555 Pickup Date: 07/02/2012 Pickup City or Zip: 12938 Drop Off City or Zip: 23981 Year: 2009 Make: Audi Model: A4 Carrier Type: enclosed carrier This Quote is from awebsite.com
这是我自己发邮件时收到的内容。
Domestic Quote Request
Full Name: Test
Email: someone@somewhere.com
Phone: 555-555-5555
Pickup Date: 07/02/2012
Pickup City or Zip: 12938
Drop Off City or Zip: 23981
Year: 2009
Make: Audi
Model: M4
Carrier Type: enclosed carrier
This Quote is from awebsite.com
该公司表示,他们认为该线索是以自由文本而非纯文本形式发送的。有这样的事吗?我从未听说过自由文本。
提前感谢您的帮助。
答案 0 :(得分:0)
我唯一能想到的是他们正在查看电子邮件的网络客户端用HTML解析电子邮件。因此,而不是\ n尝试<br />
。
答案 1 :(得分:0)
电子邮件正文需要Microsoft \ r \ n行结尾。 标题需要Linux \ n行结尾。