溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

ThinkPHP_phpmailer使用外部認證SMTP發送郵件

發布時間:2020-06-09 12:12:34 來源:網絡 閱讀:786 作者:pgmia 欄目:web開發

一、軟件版本

Apache Apache/2.2.22

ThinkPHP 1.5.0

php 5.3.10(enable socket)


二、phpmailer相關文件


phpmailer.class.php

smtp.class.php


三、軟件部署方式


復制phpmailer.class.php、smtp.class.php到Web的Common(/usr/local/apache2/htdocs/Common)目錄下,

復制phpmailer.class.php到ThinkPHP\Vender(/usr/local/apache2/htdocs/ThinkPHP/Vendor)目錄下


1.common.php


<?PHP

require_once(COMMON_PATH.'phpmailer.class.php');

require_once(COMMON_PATH.'smtp.class.php');


function SendMail($address,$title,$message){

    vendor('PHPMailer.class#PHPMailer');

    $mail=new PHPMailer();

    $mail->IsSMTP();

    $body = eregi_replace("[\]",'',$message);

    $mail->CharSet='GBK';

    $mail->AddAddress($address);

    $mail->Body=$message;

    $mail->From=C('MAIL_ADDRESS');

    $mail->FromName='yyjk';

    $mail->Subject=$title;

    $mail->Host=C('MAIL_SMTP');

    $mail->SMTPAuth=true;

    $mail->Username=C('MAIL_LOGINNAME');

    $mail->Password=C('MAIL_PASSWORD');

    $mail->MsgHTML($body);

    return($mail->Send());

}


?>


2.config.php


/usr/local/apache2/htdocs/Conf


編輯Conf目錄下的config.php,在return array添加如下內容

'MAIL_ADDRESS'=>'xxx@126.com', // 郵箱地址

'MAIL_SMTP'=>'smtp.126.com', // 郵箱SMTP服務器

'MAIL_LOGINNAME'=>'xxx', // 郵箱登錄帳號

'MAIL_PASSWORD'=>'xxx', // 郵箱密碼



3.在Action中發送郵件


/usr/local/apache2/htdocs/Lib/Action


由于ThinkPHP會自動加載common.php中的函數,所以在需要發送郵件的時候,只需要使用如下代碼即可。

SendMail("xxx@xxx.com","郵件標題","郵件正文");

至此,發送郵件的功能已經實現。撒花!歡迎成功配置的同學SendMail("yuanmouren1hao@sina.cn","我看了教程會發郵件了~~","謝啦,謝啦~~");

QQ郵箱(含foxmail)和網易的126、163都測試成功。


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女