PHP mail()函數(shù)使用及配置方法
配置
工欲善其事,必先利其器。首先我們以windows下面為例進行說明,如何配置一下本地的mail。
下載附件 sendmail.zip
-解壓到任意路徑,修改sendmail.ini,根據(jù)實際需要修改下面的信息。
[sendmail]
smtp_server=smtp.qq.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=***@qq.com
auth_password=***
force_sender=***@qq.com
-php.ini
[mail function]
SMTP = smtp.qq.com
smtp_port = 25
sendmail_from = ***@qq.com
sendmail_path = "D:/sendmail/sendmail.exe -t -i"
mail.add_x_header = On
注意:
目前測試只是qq發(fā)送成功,163的不成功可能是他有過濾系統(tǒng),可以成功發(fā)送給gmail。
語法
定義和用法
mail() 函數(shù)允許您從腳本中直接發(fā)送電子郵件。
如果郵件的投遞被成功地接收,則返回 true,否則返回 false。
說明
在 message 參數(shù)規(guī)定的消息中,行之間必須以一個 LF(\n)分隔。每行不能超過 70 個字符。
(Windows 下)當 PHP 直接連接到 SMTP 服務器時,如果在一行開頭發(fā)現(xiàn)一個句號,則會被刪掉。要避免此問題,將單個句號替換成兩個句號。
<?php
$text = str_replace("\n.", "\n..", $text);
?>
提示和注釋
注釋:您需要緊記,郵件投遞被接受,并不意味著郵件到達了計劃的目的地。
示例
下面引用一個官方的發(fā)送HTML郵件的例子。
<?php
$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// 當發(fā)送 HTML 電子郵件時,請始終設置 content-type
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
// 更多報頭
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>
相關文章
php在頁面中調(diào)用fckeditor編輯器的方法
fckeditor編輯器的代碼可以寫成一個函數(shù)或者類別,直接調(diào)用,不用每次都要寫那么多代碼!2011-06-06
php使用指定編碼導出mysql數(shù)據(jù)到csv文件的方法
這篇文章主要介紹了php使用指定編碼導出mysql數(shù)據(jù)到csv文件的方法,涉及php查詢mysql及操作csv文件的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03
PHP實現(xiàn)對png圖像進行縮放的方法(支持透明背景)
這篇文章主要介紹了PHP實現(xiàn)對png圖像進行縮放的方法(支持透明背景),可實現(xiàn)php針對png圖像的縮放功能,且支持透明背景,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07

