composer require phpmailer/phpmailer
簡單實(shí)例
<?php
namespace app\common\event;
class EMail {
function send($to, $name, $subject = '', $body = '', $attachment = null) {
$mail = new \PHPMailer\PHPMailer\PHPMailer(); //實(shí)例化PHPMailer對象
$mail->CharSet = 'UTF-8'; //設(shè)定郵件編碼,默認(rèn)ISO-8859-1,如果發(fā)中文此項(xiàng)必須設(shè)置,否則亂碼
$mail->IsSMTP(); // 設(shè)定使用SMTP服務(wù)
$mail->SMTPDebug = 1; // SMTP調(diào)試功能 0=關(guān)閉 1 = 錯誤和消息 2 = 消息
$mail->SMTPAuth = true; // 啟用 SMTP 驗(yàn)證功能
$mail->SMTPSecure = 'ssl'; // 使用安全協(xié)議
// $mail->Host = "smtp.exmail.qq.com"; // SMTP 服務(wù)器
$mail->Host = "smtp.qq.com"; // SMTP 服務(wù)器
$mail->Port = 465; // SMTP服務(wù)器的端口號
$mail->Username = "xxxx@qq.com"; // SMTP服務(wù)器用戶名
$mail->Password = "xxxx"; // SMTP服務(wù)器密碼
$mail->SetFrom('xxxxx@qq.com', '發(fā)送人名稱');
$replyEmail = ''; //留空則為發(fā)件人EMAIL
$replyName = ''; //回復(fù)名稱(留空則為發(fā)件人名稱)
$mail->AddReplyTo($replyEmail, $replyName);
$mail->Subject = $subject;
$mail->MsgHTML($body);
$mail->AddAddress($to, $name);
if (is_array($attachment)) { // 添加附件
foreach ($attachment as $file) {
is_file($file) && $mail->AddAttachment($file);
}
}
return $mail->Send() ? true : true;//$mail->ErrorInfo;
}
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)站題目:ThinkPHP5實(shí)現(xiàn)smtp發(fā)送郵件簡易實(shí)例-創(chuàng)新互聯(lián)
URL網(wǎng)址:http://www.chinadenli.net/article22/dsoscc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、品牌網(wǎng)站制作、定制網(wǎng)站、網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、微信公眾號
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容