Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

php - Complete mail header

I need a set of mail headers to attach to my mail() function in PHP. I send emails with HTML in them, and sometimes services like Yahoo Mail block them. Therefore I need to make sure that I am at least providing the right headers.

My code:

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

// Additional headers
$headers .= 'From: MyCompany <welcome@mycompany.com>' . "
";  

Is there anything else I should add?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
    $headers  = "From: testsite <mail@testsite.com>
";
    $headers .= "Cc: testsite <mail@testsite.com>
"; 
    $headers .= "X-Sender: testsite <mail@testsite.com>
";
    $headers .= 'X-Mailer: PHP/' . phpversion();
    $headers .= "X-Priority: 1
"; // Urgent message!
    $headers .= "Return-Path: mail@testsite.com
"; // Return path for errors
    $headers .= "MIME-Version: 1.0
";
    $headers .= "Content-Type: text/html; charset=iso-8859-1
";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...