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