本文目錄一覽:
PHP如何使用MAIL函數發郵件
PHP mail 發送郵件
(PHP 4, PHP 5)
mail — 發送郵件
說明
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
發送一封電子郵件。
參數
to
電子郵件收件人,或收件人列表。
本字符串的格式必須符合 » RFC 2822。例如:
user@example.com
user@example.com, anotheruser@example.com
User user@example.com
User user@example.com, Another User anotheruser@example.com
subject
電子郵件的主題。
Caution
本項不能包含任何換行符,否則郵件可能無法正確發送。
message
所要發送的消息。
行之間必須以一個 LF( )分隔。每行不能超過 70 個字符。
Caution
(Windows 下)當 PHP 直接連接到 SMTP 服務器時,如果在一行開頭髮現一個句號,則會被刪掉。要避免此問題,將單個句號替換成兩個句號。 ?php
$text = str_replace(” .”, ” ..”, $text);
?
additional_headers(可選項)
String to be inserted at the end of the email header.
This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF ( ).
如何使用php的mail函數發送郵件
如果需要用php的mail()函數來發送郵件,是需要服務器安裝sendmail組件才能支持的,這個在php的手冊中mail()函數部分也有介紹到。在Ubuntu下安裝sendmail的命令:sudo apt-get install sendmail安裝好之後,啟動sendmail服務:sudo service sendmail start有了sendmail的支持,就可以在php中用mail()函數發送郵件了。
如何使用php中的mail函數發送html格式的信
採用 phpmailer類,來做郵件發送,是很多PHP程序所採用的一個類發送
require(ROOT.’/class/phpMailer.class.php’);//郵件發送類
/**
* 發送郵件
* @param string $to 接收人郵件地址
* @param string $title 郵件標題
* @param string $contents 郵件內容 支持HTML格式
* @param string $type 判斷是否要加附件
* @param string $accessory 附件的名字
* @return 成功返回true,失敗返回錯誤信息
*/
function sendEmail($to,$title,$contents,$type = ”,$accessory =”){
$mail = new PhpMailer(true);
$mail-IsSMTP();
$mail-CharSet =”UTF-8″;//編碼
$mail-Debugoutput = ‘html’;// 支持HTML格式
$mail-Host = T_SMTP_SERVER;//HOST 地址
$mail-Port = 25;//端口
$mail-SMTPAuth = true;
$mail-Username = T_SMTP_LOGIN;//用戶名
$mail-Password = T_SMTP_PASSWORD;//密碼
$mail-SetFrom(T_SMTP_FROM,T_SMTP_FROM_NAME);//發件人地址, 發件人名稱
$mail-AddAddress($to);//收信人地址
//$mail-Subject = “=?utf-8?B?” . base64_encode() . “?=”;
if (!empty($type)) {
$mail-AddAttachment($type,$accessory); // 添加附件,並指定名稱
}
$mail-Subject = $title;//郵件標題
$mail-MsgHTML($contents);
if ($mail-Send()){
return true;
}else{
return $mail-errorMessage();
}
}
原創文章,作者:WE0TT,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/130243.html