這篇文章主要介紹了php發送html格式文本郵件的方法,涉及MIME版本、字符集、內容類型等的相關設置技巧,需要的朋友可以參考下
本文實例講述了php發送html格式文本郵件的方法。分享給大家供大家參考。具體實現方法如下:
- <?php
- $to = "simon@mailexample.com, elaine@mailexample.com"; //設置收件人
- $subject = "This is a test"; //設置E-mail主題
- //設置E-mail內容:
- $message = "
- <html>
- <head>
- <title>This is a test</title>
- </head>
- <body>
- <p>Dear all,</p>
- <p>This is a test for HTML mail sending.</p>
- </body>
- </html>
- ";
- //設置郵件頭Content-type header
- $header = "MIME-Version: 1.0/r/n"; //設置MIME版本
- $header .= "Content-type: text/html; charset=iso-8859-1/r/n"; //設置內容類型和字符集
- //設置收件人、發件人信息
- $header .= "To: Simon <simon@mailexample.com>, Elaine <elaine@mailexample.com>/r/n"; //設置收件人
- $header .= "From: PHP Tester <phptester@163.com>/r/n"; //設置發件人
- $header .= "Cc: Peter@mailexample.com/r/n"; // 設置抄送
- $header .= "Bcc: David@mailexample.com/r/n"; // 設置暗抄
- echo $header;
- mail($to, $subject, $message, $header); //發送郵件
- ?>
希望本文所述對大家的php程序設計有所幫助。
新聞熱點
疑難解答