Example of the WordPress website email sending function

Source: Internet
Author: User
Tags php file


Windows hosts cannot support the mail () function, so they cannot use the mailbox service provided by WordPress. The mail sending function is essential for a website, for webmasters who use WordPress to build websites, in addition to sending emails using the host email function, you can also use the WP plug-in or directly modify the WP code to implement the email sending function on the WP website.

Next we will discuss how to use the SMTP plug-in of WP and modify the WP code to implement the Mail sending function.

1. Use the SMTP plug-in of WP to implement the Mail function

The SMTP plug-in of WP is made by Chinese people, and the setting interface is very simple. It is a Chinese plug-in.

The wp smtp plug-in has been officially indexed by WordPress and comes with a simplified Chinese package, and can be automatically deleted when uninstalling it.

On the top of the settings page of wp smtp, you can click the corresponding icon to view the sample screenshot. As shown in the following figure:

 

After configuration, you can enter the recipient and email content:

 

 

2. Modify the WP code to implement the Mail function.

Find the functions. Php file in the wordpress webpage file and open the editing file.

 

<Span style = "color: # ff0000;"> & lt ;? Php </span> <span style = "font-family: Georgia, 'Times New Roman ', 'Bitstream Charter', Times, serif; "> and </span> <span style =" color: # ff0000; ">? & Gt; </span>

Add the following code:

Add_action ('phpmailer _ init', 'mail _ smtp '); function mail_smtp ($ phpmailer) {$ phpmailer-> IsSMTP (); $ phpmailer-> SMTPAuth = true; // enable the SMTPAuth service $ phpmailer-> Port = 465; // SMTP mail sending Port, which corresponds to the following. If you enter 25 here, $ phpmailer-> SMTPSecure = "ssl" is not entered below; // whether to verify ssl. This corresponds to the above. If not entered, then the above Port must be 25 $ phpmailer-> Host = "smtp.zhuji91.com"; // SMTP server address of the mailbox. If it is Google's, it will be: smtp.gmail.com $ phpmailer-> Username = "admin@zhuji91.com"; // your email address $ phpmailer-> Password = "*****"; // your email login Password}

I personally think that the method of adding a plug-in is simpler and faster, but the method of modifying the code is also good. I hope it can help you.

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.