Use PHPMailer to write code for sending emails
Create a new functions.php file
The code is as follows:
<?php /*發(fā)送郵件方法 *@param $to:接收者 $title:標(biāo)題 $content:郵件內(nèi)容 *@return bool true:發(fā)送成功 false:發(fā)送失敗 */ function sendMail($to,$title,$content){ //引入PHPMailer的核心文件 使用require_once包含避免出現(xiàn)PHPMailer類重復(fù)定義的警告 require_once("./class.phpmailer.php"); require_once("./class.smtp.php"); $mail = new PHPMailer();//實(shí)例化PHPMailer核心類 // $mail->SMTPDebug = 1;//是否啟用smtp的debug進(jìn)行調(diào)試 開(kāi)發(fā)環(huán)境建議開(kāi)啟 生產(chǎn)環(huán)境注釋掉即可 默認(rèn)關(guān)閉debug調(diào)試模式 $mail->isSMTP();//使用smtp鑒權(quán)方式發(fā)送郵件 $mail->SMTPAuth=true;//smtp需要鑒權(quán) 這個(gè)必須是true $mail->Host = 'smtp.qq.com';//鏈接qq域名郵箱的服務(wù)器地址 $mail->SMTPSecure = 'ssl';//設(shè)置使用ssl加密方式登錄鑒權(quán) $mail->Port = 465;//設(shè)置ssl連接smtp服務(wù)器的遠(yuǎn)程服務(wù)器端口號(hào),以前的默認(rèn)是25,但是現(xiàn)在新的好像已經(jīng)不可用了 可選465或587 $mail->CharSet = 'UTF-8';//設(shè)置發(fā)送的郵件的編碼 可選GB2312 我喜歡utf-8 據(jù)說(shuō)utf8在某些客戶端收信下會(huì)亂碼 $mail->FromName = '歡迎加入PHP中文網(wǎng)';//設(shè)置發(fā)件人姓名(昵稱) 任意內(nèi)容,顯示在收件人郵件的發(fā)件人郵箱地址前的發(fā)件人姓名 $mail->Username ='1170556238@qq.com';//smtp登錄的賬號(hào) 這里填入字符串格式的qq號(hào)即可 $mail->Password = 'llnd*******hfgfa';//smtp登錄的密碼 使用生成的授權(quán)碼(就剛才叫你保存的最新的授權(quán)碼)【非常重要:在網(wǎng)頁(yè)上登陸郵箱后在設(shè)置中去獲取此授權(quán)碼】 $mail->From = '1170556238@qq.com';//設(shè)置發(fā)件人郵箱地址 這里填入上述提到的“發(fā)件人郵箱” $mail->isHTML(true);//郵件正文是否為html編碼 注意此處是一個(gè)方法 不再是屬性 true或false $mail->addAddress($to);//設(shè)置收件人郵箱地址 $mail->Subject = $title;//添加該郵件的主題 $mail->Body = $content;//添加郵件正文 上方將isHTML設(shè)置成了true,則可以是完整的html字符串 如:使用file_get_contents函數(shù)讀取本地的html文件 //簡(jiǎn)單的判斷與提示信息 if($mail->send()) { return true; }else{ return false; } } ?>
You only need to modify the sender’s link qq domain name email address The server address, smtp login account, and smtp login password can be
Get the smtp login password here: