Sending email in WordPress is very common, some common cases are that WordPress could send out notification emails when people register an account with your website, or submit a comment. To properly send the email, you will need to setup something in your WordPress site, in below WordPress tutorials, we will share how.
Send WordPress Emails with SMTP Server
To be frank, this is not a difficult thing for the majority of WordPress users. You simply need to leverage your control panel and the WordPress plugin named as WP Mail SMTP. Note that you can find many other useful WordPress SMTP plugins for the better email security.
Step 1 – Create the Email Account
To start the process, you firstly need to create a new email account you prefer with the control panel offered by your web host. In the following, we simply take the widely-used cPanel control panel as an example.
After logging into your cPanel, you can find the icon of Email Accounts from the Email area. Simply click it, and fill out all the information in the following screenshot.
As all the aspects are set up properly, you can click the Create Account button to get your new email account.
Step 2 – Get the SMTP Host and SMTP Port
Now, you need to get two things for the successful utilization of SMTP for email sending. One is the host name of SMTP for your email, and the other is the SMTP port for the secured login.
If you decide to use the SMTP server offered by your web host, you can contact their support team to ask for the information. Some web hosts even showcase these two aspects in their WIKI page or knowledge base.
On the other hand, if you choose some popular SMTP servers offered by Gmail, Yahoo and Hotmail, you can refer to the following listed information directly. If you use none of them, you need to check the required information from search engines.
- Host Name – smtp.gmail.com for Gmail, smtp.mail.yahoo.com for Yahoo and smtp.live.com for Hotmail.
- Port Number – 587 for Gmail, 465 for Yahoo and 587 for Hotmail.
Step 3 – Install and Configure the WP Mail SMTP Plugin
After installing and activating this plugin in your WordPress dashboard, you can click the newly added Email button from the drop-down menu of Settings. After filling out all the required information, you can start sending emails at once.
First of all, you need to decide the basic settings of this plugin, which include the “From Email Address” and the “From Name”. The former one is the email address you have created in the step 1. As for the latter one, it is recommended to use your website name. Note that if you leave this option in blank, then the default name will be WordPress.
Besides, as for the Mailer, you need to choose the option of sending all the WordPress emails using SMTP.
Next, you should configure the SMTP options. Here, you firstly need to enter the SMTP host name and port number you have gained in the step 2 correctly. As for the Encryption, it depends on your website configuration. However, you need to know that the port numbers for SSL encryption and TLS encryption might be different. For instance, if you use Gmail SMTP, you need to enter 587 as the port number for TLS encryption and the 465 for SSL encryption.
In addition, do not forget to click the Yes box in the Authentication section for the activation of SMTP authentication.
Lastly, you need to enter your email address and corresponding password into the Username and Password blank space.
Now, click the Save Changes button.
Step 4 – Test Your Email
This plugin is great that allows you to send a test email. You only need to type an email address and click the Send Test button. If your recipient gets the testing message, you can start sending emails using SMTP without any worry.
Send Emails in WordPress Using PHP
If you want to do send email in WordPress using PHP, several codes can help you achieve it and what you need to do is just copy the code in below, and then make some subtle changes. Before copy those codes, you need somewhere to place it. Fortunately for us, WordPress offers wp_mail automatically and once you copy those codes in below to that file, WordPress knows what you want to do.
This code is a standard one and the content and there are some fixed things you need to know. When you send emails, just change the content in below to meet your own needs.
- To – it means to whom you intend to send an email.
- Subject – this should be the title of the email.
- Content – this is the central part of an email.
Under many circumstances, we need to send emails to more than one people. For example, you offer a significant discount of your new product and want to let all your potential customers know it. Thus, you need to send an email to every one of them with the same content. If you do this one by one, that is a big task that can waste a lot of time. But don’t worry; you can set multiple recipients with the following codes.
Apart from those basic functions, we offer codes in below, with which you can change the header of an email. This is very useful when you want to get a reply. For example, the default header is From, and you can change it to Reply-To.