【问题标题】:How to format email using SMTP如何使用 SMTP 格式化电子邮件
【发布时间】:2012-05-11 11:29:56
【问题描述】:

我正在尝试使用 php smtp 身份验证 发送格式化的电子邮件,但由于某些原因,\n\r\nPHP_EOL 无法格式化邮件,因此一切都出现了在一条线上。

以下是我尝试过的

$order .= "Title : {$title}" . PHP_EOL
."Author : {$author}" . PHP_EOL
."ISBN : {$isbn}" . PHP_EOL
."Publisher : {$publisher}" . PHP_EOL
."Supplier : {$supplier}\n
Quantity : {$qty}\r\n   

变量$order 包含电子邮件的正文。 这是我的sendMail() 函数的一部分

$from = "{$sender_name} <{$sender}>";
$to = $reciever." <$email>";
$subject = $subj;
$body = $msg;
$host = "mail.thekingsbooks.com";           
$username = "noreply@thekingsbooks.com";
$password = "password";

$headers = array(
  'From'    => $from, 
  'To'      => $to, 
  'Subject' => $subject
);

$smtp = Mail::factory(
  'smtp',
   array(
     'host'   => $host, 
     'auth'   => true,
     username => $username, 
     password => $password
   )
 );

$mail = $smtp->send($to, $headers, $body);

发送的邮件如下所示

Ordered items\r\nTitle : A Retreat With Pope John Paul II: Be Not Afraid (Retreat With-- Series)\r\nAuthor : \r\nISBN : 0867164204\r\nPublisher : \r\nSupplier : \r\n\r\n                               Quantity : 6\r\n\r\n         

关于如何格式化电子邮件正文有什么建议吗?谢谢

【问题讨论】:

    标签: php email formatting smtp


    【解决方案1】:

    如果您在 Outlook 中查看此内容,则 Outlook 可能会删除空格。在 Outlook 中,单击显示已恢复空白的选项。

    【讨论】:

    • 我发邮件到gmail,我没有用outlook。
    【解决方案2】:

    它可能是作为 HTML 发送的。尝试将“Content-type: text/plain; charset=iso-8859-1”添加到您的标题中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-19
      • 1970-01-01
      • 1970-01-01
      • 2011-02-20
      • 1970-01-01
      • 1970-01-01
      • 2016-04-17
      • 1970-01-01
      相关资源
      最近更新 更多