Home > Article > Backend Development > How to send emails using Thinphp_PHP Tutorial
I haven’t used php for a long time, and suddenly I wanted to use thinkphp to send emails, but the books I checked were very messy, so I didn’t continue reading. I found a better method here:
Step one: First we need to introduce an external class library: Mail.class.php
Put it in the ORG directory (which is the core directory of thinkphp, if you still don’t understand, see the picture below):
In this way, we have introduced the relevant class libraries. The download address of the class library is as follows: Mail.class.php
Step 2:
Add the following configuration information to the common/conf/config.php file (do not copy, the following is your email address):
//Configure email related information
'MAIL_ADDRESS'=>'18753377393@163.com', // Email address
'MAIL_SMTP'=>'smtp.163.com', // Email SMTP server
'MAIL_LOGINNAME'=>'18753377393', // Email login account
'MAIL_PASSWORD'=>'123456789', // Email password
'MAIL_CHARSET'=>'UTF-8',//Encoding
'MAIL_AUTH'=>true,//Email authentication
'MAIL_HTML'=>true,//true HTML format false TXT format
At this time, the configuration of the email function has been completed. The next step is to send:
Step 3: Send email:
Within a specific controller method:
import('.ORG.Mail');//Introducing the mail class
SendMail('Destination address', 'Email title', 'Text', 'Sender'); //The destination address is the email address of the person you want to send it to
After completion, the last step is to check whether the recipient’s mailbox has received the email and whether the format of the email is correct.