Thinkphp_phpmailer sending mail using external authentication SMTP

Source: Internet
Author: User

First, the software version

Apache apache/2.2.22

thinkphp 1.5.0

PHP 5.3.10 (Enable socket)


Ii. Related Documents of Phpmailer


phpmailer.class.php

smtp.class.php


Third, the software deployment method


Copy the phpmailer.class.php, smtp.class.php to the Web Common (/usr/local/apache2/htdocs/common) directory,

Copy phpmailer.class.php to Thinkphp\vender (/usr/local/apache2/htdocs/thinkphp/vendor) directory


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


Edit the config.php in the Conf directory and add the following to the return array

' Mail_address ' = ' [email protected] ',//email address

' Mail_smtp ' = ' smtp.126.com ',//mailbox SMTP Server

' Mail_loginname ' = ' xxx ',//Email login account

' Mail_password ' = ' xxx ',//email password



3. Send a message in action


/usr/local/apache2/htdocs/lib/action


Since thinkphp will automatically load functions in common.php, it is only necessary to use the following code when sending a message.

SendMail ("[Email protected]", "Mail Header", "message body");

At this point, the ability to send mail has been implemented. Sprinkle the flowers! Welcome to the successful configuration of the classmate SendMail ("[Email protected]", "I read the tutorial will send mail ~ ~", "Xie, Xie ~ ~");

QQ mailbox (including Foxmail) and NetEase's 126, 163 are tested successfully.


This article is from the "Yiyi" blog, make sure to keep this source http://heyiyi.blog.51cto.com/205455/1672501

Thinkphp_phpmailer sending mail using external authentication SMTP

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.