Linuxはsendmailを配置してPHPを実現してメールを送信します

1315 ワード

Linuxはsendmailを配置してPHPを実現してメールを送信します
1.sendmailのインストール
yum -y install sendmail

2.mailコマンドのインストール
yum -y install mailx

3.sendmailを開く
/etc/rc.d/init.d/sendmail start

4.起動の設定
vim /etc/rc.local

最後の行を追加:
/etc/rc.d/init.d/sendmail start

5.このとき、簡単なmail関数を1つ書いてメールを送ることができます.
mail(“   email“,”    ”,”    ”,”from:   email”);

しかし、次の問題があります.
1.メールタイトル、内容中国語文字化けし
2.メールの内容はhtmlをサポートしていません
 
6.最適化
$from = '   email';
$to = '   email';
$title = '    123!@#¥%……&*()subject';
$subject = "=?UTF-8?B?".base64_encode($title)."?="; //        
$body = 'link';
//         html
$headers[] = "From: $from";
$headers[] = "X-Mailer: PHP";
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=utf8";
$headers[] = "Reply-To: $from"; 
mail($to, $subject, $body, implode("\r
", $headers), "-f $from");

直接php.iniで修正し、
[html]  view plain copy
sendmail_path = /usr/sbin/sendmail -f [email protected] -t -i