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