Thinkphp3.2 phpmailer Send mail

Source: Internet
Author: User

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
  1. /**
  2. * Mail Send function
  3.  */
  4. function sendMail($to, $title, $ Content) {
  5.      
  6. Vendor(' phpmailer.phpmailerautoload ');      
  7. $mail = new phpmailer(); //instantiation
  8. $mail - ISSMTP (); //Enable SMTP
  9.          $mail -> host = c ' Mail_host '   //SMTP server (for example, QQ mailbox)
  10.          $mail -> smtpauth   =  c ( ' Mail_smtpauth '   //Enable SMTP authentication
  11.          $mail -> username   =  c ( ' Mail_username '   //your mailbox name
  12.          $mail -> password   =  c ( ' Mail_password ' )     //Mailbox password
  13.          $mail -> from   =  c ( ' Mail_from '   //Sender address (that is, your e-mail address)
  14. $mail - FromName = C(' mail_fromname '); //Sender name
  15. $mail - addaddress ($to,"Dear Customer");
  16. $mail - WordWrap = +; //Set character length per line
  17. $mail - ishtml (C(' mail_ishtml ')); //Whether HTML-formatted mail
  18. $mail - CharSet = C (' mail_charset '); //Set message encoding
  19. $mail - Subject =$title; //Mail subject
  20. $mail - Body = $content; //email content
  21. $mail - Altbody = "This is a plain text body in the non-profit HTML email client"; //message body does not support alternate display of HTML
  22. return($mail,Send());
  23.     }
Copy Code Add a configuration file

config.php
  1. //configure mail sending server
  2. ' mail_host ' ='smtp.exmail.qq.com ',name of the//SMTP server
  3. ' Mail_smtpauth ' =TRUE, // Enable SMTP authentication
  4. ' mail_username ' ='[email protected] ',//Your mailbox name
  5. ' mail_from ' ='[email protected] ',//Sender Address
  6. ' mail_fromname '=' poly Fung Group ',//Sender name
  7. ' mail_password ' ='****** ',//Email password
  8. ' mail_charset ' +' utf-8 ',//Set message encoding
  9. ' mail_ishtml ' =TRUE, //Whether HTML-formatted mail
Copy Code The end is to send mail using Phpmailer
  1. <form &NBSP; action = "__url__/add" &NBSP; method = "POST" &NBSP; enctype = "Multipart/form-data" >
  2. <input &NBSP;&NBSP; type = &NBSP; id = "Mail" &NBSP; name = "Mail" />
  3.      title: <input &NBSP;&NBSP; type = &NBSP; id = "title" &NBSP; name = />
  4. content <input type="text" id="Content" name = "Content" />
  5.     <input class="button" type="Submit" value="Send" style="margin: 0 Auto;Display:Block;"/>
  6. </form>
Copy Code
  1. Public function add() {
  2.              if ( ( $_post [ Mail ' ", ' title ' ], $_post [
  3. $this - Success (' sent successfully! ');
  4. Else
  5. $this - Error (' send failed ');
  6.  }
Copy Code

Phpmailer:https://github.com/phpmailer/phpmailer

Thinkphp3.2 phpmailer Send mail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.