Thinkphp3.2 phpmailer Send mail combined with QQ Enterprise mailbox to send mail
Download Attachment Phpmailer extract to Thinkphp\library\vendor
Create a new function.php in the common folder
- /**
- * Mail Send function
- */
- function sendMail($to, $title, $ Content) {
-
- Vendor(' phpmailer.phpmailerautoload ');
- $mail = new phpmailer(); //instantiation
- $mail - ISSMTP (); //Enable SMTP
- $mail -> host = c ' Mail_host '   //SMTP server (for example, QQ mailbox)
- $mail -> smtpauth   = c ( ' Mail_smtpauth '   //Enable SMTP authentication
- $mail -> username   = c ( ' Mail_username '   //your mailbox name
- $mail -> password   = c ( ' Mail_password ' )     //Mailbox password
- $mail -> from   = c ( ' Mail_from '   //Sender address (that is, your e-mail address)
- $mail - FromName = C(' mail_fromname '); //Sender name
- $mail - addaddress ($to,"Dear Customer");
- $mail - WordWrap = +; //Set character length per line
- $mail - ishtml (C(' mail_ishtml ')); //Whether HTML-formatted mail
- $mail - CharSet = C (' mail_charset '); //Set message encoding
- $mail - Subject =$title; //Mail subject
- $mail - Body = $content; //email content
- $mail - Altbody = "This is a plain text body in the non-profit HTML email client"; //message body does not support alternate display of HTML
- return($mail,Send());
- }
Copy Code Add a configuration file
config.php
- //configure mail sending server
- ' mail_host ' ='smtp.exmail.qq.com ',name of the//SMTP server
- ' Mail_smtpauth ' =TRUE, // Enable SMTP authentication
- ' mail_username ' ='[email protected] ',//Your mailbox name
- ' mail_from ' ='[email protected] ',//Sender Address
- ' mail_fromname '=' poly Fung Group ',//Sender name
- ' mail_password ' ='****** ',//Email password
- ' mail_charset ' +' utf-8 ',//Set message encoding
- ' mail_ishtml ' =TRUE, //Whether HTML-formatted mail
Copy Code The end is to send mail using Phpmailer
- <form &NBSP; action = "__url__/add" &NBSP; method = "POST" &NBSP; enctype = "Multipart/form-data" >
- <input &NBSP;&NBSP; type = &NBSP; id = "Mail" &NBSP; name = "Mail" />
- title: <input &NBSP;&NBSP; type = &NBSP; id = "title" &NBSP; name = />
- content <input type="text" id="Content" name = "Content" />
- <input class="button" type="Submit" value="Send" style="margin: 0 Auto;Display:Block;"/>
- </form>
Copy Code
- Public function add() {
- if ( ( $_post [ Mail ' ", ' title ' ], $_post [
- $this - Success (' sent successfully! ');
- Else
- $this - Error (' send failed ');
- }
Copy Code
Phpmailer:https://github.com/phpmailer/phpmailer
Thinkphp3.2 phpmailer Send mail