是否可以使用php邮件功能发送混合的txt / html邮件? [英] Is it possible to send mixed txt/html mails with the php mail function?

查看:160
本文介绍了是否可以使用php邮件功能发送混合的txt / html邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了很多测试,我尝试了两个解决方案:

I'm doingsome tests, I tried two solutions so far:

第一个发送消息到头(mail()函数的message参数空)[]

The first one sends the message inside the headers (message parameter of the mail() function is empty) []

    $boundary = "nextPart";
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "From: ".$from_name." <".$from.">\r\n";
    $headers .= "Content-Type: multipart/alternative; boundary = $boundary\r\n";
    //Html
    $headers .= "\n--$boundary\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= $html;
    //Text
    $headers .= "\n--$boundary\n";
    $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
    $headers .= $text;

第二个是这个: http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php#attachment (设置标题并将其发送到消息内)

The second one is this one: http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php#attachment (set headers and sends them inside the message)

其中没有正常工作(第一个不起作用,第二个工作在gmail中,但它不是格式正确的电子邮件,有些客户端无法处理) 。
解析php邮件程序的代码( http://phpmailer.worxware.com /index.php?pg=phpmailer )我看到它甚至没有尝试发送多部分电子邮件。

Non of them works properly (the first one doesn't work at all, the second works in gmail but it's not a properly formatted email, and some client can't handle it). Dissecting the code of php mailer (http://phpmailer.worxware.com/index.php?pg=phpmailer) i saw that it doesn't even try to send multipart emails.

所以我想知道是否可能发送具有php邮件功能的格式正确的多部分电子邮件。

So I'm wondering is it possible to send PROPERLY formatted multipart email with the php mail function.

谢谢

我知道和使用梨邮件,我只是想了解这个东西。

p.s. I know and use pear mail, I just want to understand this thing.

推荐答案

是的,这是可能的。 PHP的 mail(); 功能只不过是将原始消息传递到底层操作系统的邮件处理程序(例如sendmail)的一个方便的功能。

yes, it is possible. PHP's mail(); function is nothing more than a handy function to deliver your 'raw' message to the underlying operating system's mail handler (sendmail for example).

所以如果你的消息标题和消息体组合是一个正确的MIME编码消息,事情将正常运行。

So if your message headers- and message body combined are a correct MIME encoded message, things will work fine.

要找出一个简单的邮件客户端并分析它的电子邮件。将其与 MIME规范结合使用,您应该到达。

To figure out the details, find a simple mail client and analyse it's emails. Combine this with the MIME specifications and you should get there.

这篇关于是否可以使用php邮件功能发送混合的txt / html邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆