dongye9071
2010-02-09 23:32
采纳率: 0%
浏览 58
已采纳

Postfix搞砸了电子邮件标题!

I've set up a local dev environment on snow leopard, and have set postfix up to send email via my isp mail server.

I eventually got postfix to work after much frustration, but now when my emails send the header information is bunged up!

I'm using the following php code:

$email = "me@mydomain";
$subject = "Email tester";
$body = "Simple test";
$header = "From: me@mydomain 
";
$header .= "MIME-VERSION: 1.0
";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "
";
$phpversion = phpversion();
$header .= "X-Mailer: PHP v$phpversion
";
mail($email,$subject,$body,$header);

echo "message sent!";

The To: and Subject: headers display as they should, in the header!, but the rest display in the email body. This makes the email look like the from field in email client is empty.

I've tried a variety of php scripts, some very simple, but its the same thing, headers always displaying in the email body.

I'm thinking it could be a postfix problem, but not sure, anyone encountered this type of problem before?

图片转代码服务由CSDN问答提供 功能建议

我在雪豹上设置了一个本地开发环境,并设置了postfix以通过我的isp发送电子邮件 邮件服务器。

我终于在很多挫折之后得到了postfix工作,但是现在当我的电子邮件发送时,标题信息已经堆积了!

我' m使用以下php代码:

 
 $ email =“me @ mydomain”; 
 $ subject =“Email tester”; 
 $ body =“简单测试”; \  n $ header =“From:me @ mydomain 
 
”; 
 $ header。=“MIME-VERSION:1.0 
 
”; 
 $ header。='Content-type:text / html;  charset = iso-8859-1'。  “
 
”; 
 $ phpversion = phpversion(); 
 $ header。=“X-Mailer:PHP v $ phpversion 
 
”; 
mail($ email,$ subject,$ body,$  header); 
 
echo“message sent!”; 
  
 
 

To:和Subject:标题按标题显示在标题!中,但其余部分显示在电子邮件中 身体。 这使得电子邮件看起来像电子邮件客户端中的from字段是空的。

我尝试了各种各样的PHP脚本,有些非常简单,但是同样的事情,标题始终显示在 电子邮件正文。

我认为它可能是一个后缀问题,但不确定,之前是否有人遇到过此类问题?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douyi4297 2011-05-16 20:10
    已采纳

    Use PHP_EOL instead of in *additional_headers*, i.e. $header in your example. PHP_EOL will substitute the newline correspondingly to the OS you are running on.

    Also, message should contain LN only i.e. . This is accordingly to PHP documentation. Each line should be separated with a LF ( ). Lines should not be larger than 70 characters.

    Make sure you meet both of criterias in your script - I've tried to achieve it and finally got it working with the default configuration of Postfix.

    点赞 评论
  • douniuta4783 2010-02-09 23:44

    This is almost 100% not a Postfix problem, but something caused by your code. The body starts once a blank CRLF is seen after the headers.

    You should dump out your email body text and see if you're not accidentally introducing an extra CRLF.

    点赞 评论
  • duanke2503 2011-06-15 15:49

    Investigating this problem further (basically because I didn't want to improve lots of scripts just because of that), I've come to the point that there is a strong conflict between PHP and Postfix developers, which is not fixed until now. You can read wide info here:

    http://www.mail-archive.com/postfix-users@postfix.org/msg03226.html

    Postfix expects EOL to be LF when picking up mail from sendmail on unix and replaces that with CRLF when sending. When it gets CRLF it still replaces the LF and we get CRCRLF.

    It explains broken headers. To solve this, you must exactly know how your Postfix and PHP/mail system works. If you experience problems like described above, just use " " instead of " ". If you program a complicated system which could run on both Windows/Unix, just introduce an extra param like $eeol=" "; which will be put instead of direct " " tag and that way could be easily configured for any system.

    I suppose that's the approach Postfix author recommends:

    It would be really good if PHP application programmers formatted email messages in a consistent manner. For example, they could use a variable that contains the END-OF-LINE terminator, instead of hard-coding LF or CRLF line terminators all over the place.

    点赞 评论

相关推荐 更多相似问题