PHP plugin phpmailer Send mail

Source: Internet
Author: User
Tags php send mail
This article mainly for you in detail the PHP send mail function, a Phpmailer plug-in easy to implement the mail sending function, with a certain reference value, interested in small partners can refer to

The example of this article for everyone to share the ThinkPHP3.2.3 send the specific code, for your reference, the specific content as follows

First step: In the online down a phpmailer plugin, download unzip, here we only need to use two of them, as shown in:

Place the class.phpmailer.php and class.smtp.php two files respectively into a
thinkphp/library/vendor/phpmailer/class.phpmailer.php (note case)
thinkphp/library/vendor/phpmailer/class.smtp.php

Note: The thinkphp default third-party class library Directory is now placed, if defined in index.php such as define (' Vendor_path ', App_path. ' common/vendor/'); Then the file should be placed in the same path, lest the class ' Phpmailer ' not found the case.

2, create the user-defined function file application/home/common/function.php, put the following functions:

/** * function: Mail Send function * @param string $to target mailbox * @param string $subject message subject (title) * @param s  Tring $to Message Contents * @return BOOL True */function SendMail ($to, $subject, $content) {vendor (' phpmailer.class#smtp '); Vendor (' Phpmailer.class#phpmailer '); Note that the case here, or you will not find the class, Phpmailer is the folder name, Class#phpmailer on behalf of the class.phpmailer.php file name $mail = new Phpmailer (); Assemble the mail server if (C (' mail_smtp ')) {$mail->issmtp ();} $mail->host = C (' mail_host ');  The parameters explained here are described in the following configuration information note $mail->smtpauth = C (' Mail_smtpauth '); $mail->username = C (' Mail_username '); $mail->password = C (' Mail_password '); $mail->smtpsecure = C (' mail_secure '); $mail->charset = C (' Mail_charset '); Assemble message header information $mail->from = C (' Mail_username '); $mail->addaddress ($to); $mail->fromname = C (' Mail_fromname '); $mail->ishtml (C (' mail_ishtml ')); Assemble message body information $mail->subject = $subject; $mail->body = $content; Send Message if (! $mail->send ()) {return FALSE;} else {return TRUE;}} 

3. In the above function, the C method is used to load some configuration information, so we have to add the following configuration information in the configuration file (default/application/home/conf/config.php):

<?php return Array (///other configuration items omitted ...//configure mail sending server ' mail_smtp '   = ' = TRUE, ' mail_host ' = '   smtp.163.com ', c2/>//Mail Send SMTP server ' Mail_smtpauth ' + TRUE, ' mail_username ' = ' 123***@163.com ',  //SMTP server login username ' Mail_ PASSWORD ' + ' 123456abc ',    //smtp server login password ' mail_secure '   = ' tls ', ' mail_charset '  = ' utf-8 ', ' MAIL _ishtml '   = ' + TRUE, ' mail_fromname ' and ' xxx website client ', ';

4, start the call, assuming that through the URL/?m=home&c=index&a=send access, then we corresponding in application/home/controller/ Add a method to the IndexController.class.php file as follows:

<?php namespace Home\controller; Use Think\controller; Class Indexcontroller extends Controller {public Function index () {   } public function Send () {  if (SendMail (' Vsiryxm@qq.com ', ' Hello! Mail header ', ' This is a test message body! ') {   echo ' sent successfully! ';  }  else{   echo ' send failed! ';  } } }

The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support topic.alibabacloud.com.

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.