代码之家  ›  专栏  ›  技术社区  ›  0plus1

是否可以使用php邮件功能发送混合的txt/html邮件?

  •  0
  • 0plus1  · 技术社区  · 15 年前

    我在做一些测试,到目前为止我尝试了两种解决方案:

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

        $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 (设置标题并将其发送到消息中)

    php邮件程序代码剖析( http://phpmailer.worxware.com/index.php?pg=phpmailer )我看到它甚至不尝试发送多部分电子邮件。

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

    谢谢你

    p、 我知道并使用梨形邮件,我只想了解这件事。

    2 回复  |  直到 15 年前
        1
  •  2
  •   Jacco    15 年前

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

    因此,如果消息头和消息体的组合是正确的MIME编码的消息,那么一切都会正常工作。

    MIME specifications 你应该去那里。

        2
  •  1
  •   user187291    15 年前

    据我所知,mail()只发送给定的内容,所以是的,完全有可能发送您想要的任何内容,包括多部分模拟。事实上,这正是邮件类(pear、phpmailer)在幕后所做的,尽管它们也可以配置为使用其他传输。

    换句话说,邮件类与“mail()”的比较就像模板引擎与“echo”的比较一样。

    推荐文章