How to implement pure code configuration of SMTP email sending function in WordPress without plug-ins

888u

Last update at :2024-06-01,Edit by888u

WordPress is a mature website open source blogging system. When we use it, we inevitably need to install some plug-ins to implement some functions. For example, WordPress itself does not have the function of sending an email system, but if you install plug-ins, I don’t really want to install it, because installing too many plug-ins is like a computer. Installing too many software will affect the smooth running of the computer. The same is true for websites. So today I will teach you how to implement the email system of the website without installing plug-ins. We just need to add the following code to the functions.php file of the theme we are currently using.

Tips: The file path is in the website root directory > wp-content > themes > themes > functions.php

//Use smtp to send emails (please set SMTP according to the email address you use)
add_action('phpmailer_init', 'mail_smtp');
function mail_smtp( $phpmailer ) {
$phpmailer->FromName = 'Yipojie'; //Sender
$phpmailer->Host = 'smtp.163.com'; //Change to the SMTP server you are using
$phpmailer->Port = 465; //SMTP port, SSL encryption is enabled
$phpmailer->Username = 'YPOJIE@YPOJIE.COM'; //Email account
$phpmailer->Password = '************'; //Enter your corresponding email password, * is used here instead
$phpmailer->From = 'YPOJIE@YPOJIE.COM'; //Your email
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = 'ssl'; //tls or ssl (port=25 is left blank, 465 is ssl)
$phpmailer->IsSMTP();
}

We use 163 emails to make an extension of the tutorial. Even though our server supports the mail() function, many friends have configured it but it doesn’t work. When testing to send emails, an error is prompted. The specific errors are as follows;

The email could not be sent. Possible reason: Your host has disabled the mail() function.

If this problem occurs, Sister Yipo has encountered it. Basically, this problem is caused by the wrong password for configuring the email, because most email providers now turn off POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV by default. Serve.

If we need to use the website to call SMTP, we need to manually activate it. Not only that, most SMTP services are different from the password for your email login. SMTP will be set to generate an independent authorization code/login password, as shown below

Below, Sister Yipo has sorted out the SMTP servers and ports of commonly used mailboxes to save everyone from searching everywhere.

Email SMTP server address Non-SSL port number SSL port number
163.com smtp.163.com 25 465 or 994
126.com smtp.126.com 25 465 or 994
qq.com smtp.qq.com 25 465 or 587
NetEase Enterprise Mailbox smtp.qiye.163.com 25 994
Tencent Enterprise Email smtp.exmail.qq.com 25 465

Recommended site search: webmaster IP, server, space service provider, check IP detailed address, server defense high defense, Korean server rental, foreign server, http proxy IP, domain name registration information query, asp free space application,

p>

How to implement pure code configuration of SMTP email sending function in WordPress without plug-ins

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码