PHP发送HTML邮件 [英] PHP Send HTML mail

查看:68
本文介绍了PHP发送HTML邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过PHP发送HTML邮件,但我似乎无法得到它的工作。



这是我的代码:

  //多个收件人
$ to ='mail';

// subject
$ subject ='Subject';

$ message
$ message =
< html>
< head>
< title>感谢< / title>
< / head>
< body>
< div>
< b>感谢您的电子邮件< / b>
< / div>
< / body>
< / html>
;

//要发送HTML邮件,必须将Content-type标头设置为
$ headers ='MIME-Version:1.0'。 \r\\\
;
$ headers。='Content-type:text / html; charset = iso-8859-1'。 \r\\\
;

//附加标题
$标题。='收件人:info< info@example.com>'。 \r\\\
;
$ headers。='From:Pynix< info@example.com>'。 \r\\\
;

//邮寄
邮件($ to,$ subject,$ message,$ headers);

当我在Outlook中收到时,它也不会显示任何发件人。



任何想法?

谢谢

解决方案

我不认为你必须在标题中放置 To:行,因为它是 mail 函数。
但是有些邮件客户端不喜欢灯头,这是我的工作:

  $ header ='From :联系< mail>'。PHP_EOL。 
'回复:< mail>'。PHP_EOL。
'MIME-Version:1.0'.PHP_EOL。
'Content-Type:text / plain;字符集= UTF-8'.PHP_EOL。
'Content-Transfer-Encoding:8bit'.PHP_EOL。
'X-Mailer:PHP /'。PHP_VERSION.PHP_EOL;


I am trying to send an HTML mail through PHP, but I can't seem to get it working.

This is my code:

    // multiple recipients
    $to  = 'mail';

    // subject
    $subject = 'Subject';

    // message
    $message = "
    <html>
    <head>
      <title>Thanks</title>
    </head>
    <body>
        <div>
            <b>Thanks for your email</b>
        </div>
    </body>
    </html>
    ";

    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Additional headers
    $headers .= 'To: info <info@example.com>' . "\r\n";
    $headers .= 'From: Pynix <info@example.com>' . "\r\n";

    // Mail it
    mail($to, $subject, $message, $headers);

This also doesn't show any sender when I receive it in Outlook.

Anyone an idea?

Thanks

解决方案

I don't think you have to put the To: line in the header as it is a parameter of the mail function. However some mail clients don't like light headers, here's mine which is working:

$header = 'From: "Contact" <mail>'.PHP_EOL.
                  'Reply-to: <mail>'.PHP_EOL.
                  'MIME-Version: 1.0'.PHP_EOL.
                  'Content-Type: text/plain; charset=utf-8'.PHP_EOL.
                  'Content-Transfer-Encoding: 8bit'.PHP_EOL.
                  'X-Mailer: PHP/'.PHP_VERSION.PHP_EOL;

这篇关于PHP发送HTML邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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