public function email(){
$email=input("post.email");//獲取收件人郵箱
//return $email;
$sendmail = \\\’xxxxxx@qq.com\\\’; //發(fā)件人郵箱
$sendmailpswd = "xxxxxxx"; //客戶端授權密碼,而不是郵箱的登錄密碼,就是手機發(fā)送短信之后彈出來的一長串的密碼
$send_name = \\\’lh\\\’;// 設置發(fā)件人信息,如郵件格式說明中的發(fā)件人,
$toemail = $email;//定義收件人的郵箱
$to_name = \\\’hl\\\’;//設置收件人信息,如郵件格式說明中的收件人
$mail = new PHPMailer();
$mail->isSMTP();// 使用SMTP服務
$mail->CharSet = "utf8";// 編碼格式為utf8,不設置編碼的話,中文會出現(xiàn)亂碼
$mail->Host = "smtp.qq.com";// 發(fā)送方的SMTP服務器地址
$mail->SMTPAuth = true;// 是否使用身份驗證
$mail->Username = $sendmail;//// 發(fā)送方的
$mail->Password = $sendmailpswd;//客戶端授權密碼,而不是郵箱的登錄密碼!
$mail->SMTPSecure = "ssl";// 使用ssl協(xié)議方式
$mail->Port = 465;// qq端口465或587)
$mail->setFrom($sendmail, $send_name);// 設置發(fā)件人信息,如郵件格式說明中的發(fā)件人,
$mail->addAddress($toemail, $to_name);// 設置收件人信息,如郵件格式說明中的收件人,
$mail->addReplyTo($sendmail, $send_name);// 設置回復人信息,指的是收件人收到郵件后,如果要回復,回復郵件將發(fā)送到的郵箱地址
$mail->Subject = "這里是郵件標題";// 郵件標題

$code=rand(100000,999999);
session("code",$code);
//return $code."—-".session("code");
$mail->Body = "郵件內(nèi)容是 <b>您的驗證碼是:$code</b>,如果非本人操作無需理會!";// 郵件正文
//$mail->AltBody = "This is the plain text純文本";// 這個是設置純文本方式顯示的正文內(nèi)容,如果不支持Html方式,就會用到這個,基本無用
if (!$mail->send()) { // 發(fā)送郵件
31 echo "Message could not be sent.";
echo "Mailer Error: " . $mail->ErrorInfo;// 輸出錯誤信息
} else {
return “發(fā)送成功”;
}
}

 

如果你就是直接的這樣寫那么你又會出現(xiàn)一系列的問題;

發(fā)送郵件我們需要一個擴展包隨便下一個phpmailer包;

我們需要里面的phpmailer.php,class.smtp.php兩個文件,放在extend文件下新建一個phpmailer文件夾下

phpmailer.php如果是class.phpmailer.php就把前面的Class去掉(我是在tp5框架)

分別在兩個文件里面加上命名空間use phpmailerphpmailer;

不然會出現(xiàn)phpmailer not found 和 smtp not found

除此之外還要把phpmailer里面的最后一個方法繼承的Exception改成 Exception

基本上直接就可以調(diào)用方法了,收到一份來自你自己的郵件;

更多關于云服務器域名注冊,虛擬主機的問題,請訪問西部數(shù)碼官網(wǎng):bingfeng168.cn

贊(0)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享網(wǎng)絡內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-62778877-8306;郵箱:fanjiao@west.cn。本站原創(chuàng)內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明出處:西部數(shù)碼知識庫 » php郵箱發(fā)送驗證碼

登錄

找回密碼

注冊