Using Phpmailer message classes in thinkphp

Source: Internet
Author: User

First step, add Phpmailer class Library
Unzip the downloaded file and move the Phpmail directory to the vendor within the thinkphp directory. (Make sure the class.phpmailer.php file is thinkphp\vendor\phpmailer\class.phpmailer.php)
Step two, add the Send mail function
Add the following code to the common.php file (if not created) in the common folder in the project directory:

<?php/********** * Send mail * **********/function SendMail ($address, $title, $message) {    vendor (' phpmailer.class# Phpmailer '); $mail =new Phpmailer ();    Set Phpmailer to use an SMTP server to send email    $mail->issmtp ();    Set the character encoding for the message, or ' UTF-8 '    $mail->charset= ' UTF-8 ' if not specified;    Add a recipient address that you can use multiple times to add multiple recipients    $mail->addaddress ($address);    Set the message body    $mail->body= $message;    Sets the From field of the message header.    $mail->from=c (' mail_address ');    Set sender name    $mail->fromname= ' lilyrecruit ';    Set the message header    $mail->subject= $title;    Set up the SMTP server.    $mail->host=c (' mail_smtp ');    Set to require validation    $mail->smtpauth=true;    Set the user name and password.    $mail->username=c (' mail_loginname ');    $mail->password=c (' Mail_password ');    Send the message.    return ($mail->send ());}? >

Step three, configure mailbox information
Edit the config.php in the Conf directory and add the following to the return array

' Mail_address ' = ' [email protected] ',//e-mail address ' mail_smtp ' + ' smtp.126.com ',//email SMTP server ' mail_loginname ' = ' xxx ',//Email login account ' mail_password ' = ' xxx ',//email password

Fourth step, send mail in action
Since thinkphp will automatically load functions in common.php, it is necessary to use the following code when sending a message
SendMail ("[Email protected]", "Mail Header", "message body");

Using Phpmailer message classes in thinkphp

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.