一個tinkphp發送郵件功能折騰了我一上午,幸好得到一個網友指導才解決這個問題,在這里我向他表示感謝,好了不多說了把源碼貼出來給大家分享一下.
下載phpmailer和郵局文件
下載地址:http://dl.vmall.com/c0ng8kxvj7
將下載的文件解壓到ThinkPHP/Extend/Library/ORG下,在控制器中將文件引入:
- class EmailAction extends Action
- {
- public function index()
- {
- if($_POST['hid']=='add')
- {
- $email=$_POST['email'];
- $title=$_POST['title'];
- $fromname=$_POST['from'];
- $toname=$_POST['to'];
- $myEditor=$_POST['myEditor'];
- $connect="系統郵件請勿回復";
- import('ORG.Mail.Phpmailer');
- $mail=new PHPMailer();
- $mail->IsSMTP();//發送郵件的模式
- $mail->CharSet = "utf-8"; //發送郵件編碼
- $mail->Encoding = "base64";
- $mail->IsHTML(true); //是否使用html格式
- $mail->Host="smtp.qq.com";//郵件服務器
- $mail->SMTPAuth=true;//啟用smtp驗證功能
- $mail->Username="[email protected]";//帳號
- $mail->Password="****";//密碼
- $mail->Port=25;//端口
- $mail->From="[email protected]";//發件人
- $mail->FromName="$fromname";//
- $mail->AddAddress("$email","$toname");
- $mail->Subject="$title";//郵件標題
- $mail->Body=$myEditor."<br>".$connect;//郵件內容
- if(!$mail->Send())
- {
- $this->error("郵件發送失敗".$mail->ErrorInfo);exit;
- }
- else
- {
- $this->success("郵件發布成功");
- }
- }else
- {
- $this->display();
- }
- }
- }
這樣就可以實現發送郵件的功能了,小小歡喜一下.
新聞熱點
疑難解答
圖片精選