A PHP Function for Sending HTML Emails

by 张宴 wrote a simple PHP function for sending HTML emails. Function description: send_mail(“sender address”, “recipient address”, “email subject”, “email body”); Example: send_mail($from, “info@zyan.cc”, “This is the email subject”, “

This is the email body

“); The code is as follows:

view plainprint?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
function send_mail($from, $to, $subject, $message)
{
    if ($from == "")
    {
        $from = '回忆未来 <webmaster@zyan.cc>';//sender address
    }
    $headers = 'MIME-Version: 1.0' . "\\r\\n";
    $headers .= 'Content-type: text/html; charset=gb2312' . "\\r\\n";
    $headers .= 'From: ' . $from . "\\r\\n";
    mail($to, $subject, $message, $headers);
}
?>