{"id":4655,"date":"2022-05-27T16:07:29","date_gmt":"2022-05-27T13:07:29","guid":{"rendered":"https:\/\/www.scalahosting.com\/kb\/?p=4655"},"modified":"2024-09-27T11:13:34","modified_gmt":"2024-09-27T08:13:34","slug":"how-to-send-wordpress-emails-via-smtp","status":"publish","type":"post","link":"https:\/\/www.scalahosting.com\/kb\/how-to-send-wordpress-emails-via-smtp\/","title":{"rendered":"How to Send WordPress Emails via SMTP"},"content":{"rendered":"\n<p><span style=\"font-weight: 400;\">It&#8217;s easy to overlook important things when working on a brand new online project. For example, when you&#8217;re building your new <\/span><a href=\"https:\/\/www.scalahosting.com\/blog\/what-is-wordpress-how-does-it-work\/\"><b>WordPress<\/b><\/a><span style=\"font-weight: 400;\"> site, you may focus all your attention on getting the content and the design right only to forget about <\/span><b>WP&#8217;s inherent email deliverability issues<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Because of them, critical messages like registration confirmation forms and password reset emails often fail to reach people&#8217;s inboxes, leading to a lot of frustration and a bad user experience.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">And usually, it all comes down to the fact that, by default, <\/span><b>WordPress doesn&#8217;t use SMTP<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><i><span style=\"font-weight: 400;\">But can you configure it to work with the protocol? Of course you can. Let&#8217;s see how.<\/span><\/i><b><\/b><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>What is SMTP, and Why Do You Need It?<\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">Because WordPress is deployed on a wide range of different hosting solutions, the CMS can&#8217;t know how each mail server is configured and what settings are required. That&#8217;s why by default, WP sends emails through<\/span><b> PHP mail() <\/b><span style=\"font-weight: 400;\">\u2013 a PHP function available on all hosting servers. Sometimes, this might just be a good enough solution, but for most people, it causes a couple of problems.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">First, the outgoing email communication bypasses the mail server, so it&#8217;s not sent over <\/span><a href=\"https:\/\/www.scalahosting.com\/kb\/what-is-my-incoming-and-outgoing-server\/\"><b>SMTP<\/b><\/a><span style=\"font-weight: 400;\">. SMTP stands for <\/span><b>Simple Mail Transfer Protocol<\/b><span style=\"font-weight: 400;\">, and it&#8217;s been the technology we&#8217;ve used for sending emails for decades. It&#8217;s <\/span><b>much more secure than the PHP function<\/b><span style=\"font-weight: 400;\">, and you can get bounceback messages in case your emails aren&#8217;t delivered.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Another problem with php mail() is that, unlike SMTP, it can&#8217;t attach <\/span><a href=\"https:\/\/www.scalahosting.com\/kb\/how-to-configure-spf-dkim-and-dmarc-records\/\"><b>SPF and DKIM signatures<\/b><\/a><span style=\"font-weight: 400;\"> to your emails. The purpose of the SFP and DKIM records is to assure mail transfer agents and the recipient server that the source of the message is legitimate. Without them, your emails are <\/span><b>very likely to be flagged as spam<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">That is, if you can send them at all.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Many hosting providers neglect to set up <\/span><b>PHP&#8217;s mailing function correctly<\/b><span style=\"font-weight: 400;\">, and some even disable it to prevent abuse and spam, especially on <\/span><a href=\"https:\/\/www.scalahosting.com\/web-hosting-for-small-business.html\"><b>shared hosting<\/b><\/a><span style=\"font-weight: 400;\"> platforms.&nbsp;<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">All in all, SMTP can give you a much more reliable and secure email communication. The only thing you need to do is enable it. You have two options.<\/span><b><\/b><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Configuring WordPress to Use SMTP Without a Plugin<\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">First, we&#8217;ll show you <\/span><b>how to configure WordPress to work with SMTP without installing plugins<\/b><span style=\"font-weight: 400;\">. It may sound a bit technical, but in essence, what we&#8217;ll do is insert a couple of code snippets into two of your website&#8217;s files \u2013 <\/span><b>wp-config.php and functions.php<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">If you&#8217;re going to use your <\/span><b>hosting account&#8217;s SMTP server<\/b><span style=\"font-weight: 400;\">, you&#8217;ll first need to set up an email address to act as a sender. You&#8217;ll need to log into your <\/span><a href=\"https:\/\/www.scalahosting.com\/spanel.html\"><b>web hosting control panel<\/b><\/a><span style=\"font-weight: 400;\"> and use the available tools to set up a new account.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">The interface may differ slightly, but you&#8217;ll most likely need to fill in a form that looks something like this.<\/span><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"864\" height=\"701\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/1-4.png\" alt=\"How to Send WordPress Emails via SMTP, Configuring WordPress to Use SMTP Without a Plugin\" class=\"wp-image-4656\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/1-4.png 864w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/1-4-300x243.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/1-4-768x623.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>\n\n\n<p><span style=\"font-weight: 400;\">This is the interface users of our <\/span><b>SPanel management platform<\/b><span style=\"font-weight: 400;\"> see. After you create the new address, you&#8217;ll see a box giving you the information on the inbox&#8217;s login credentials, the <\/span><b>IMAP\/POP3\/SMTP servers<\/b><span style=\"font-weight: 400;\">, and the networking ports.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">It&#8217;s important to remember <\/span><b>the username and password, the outgoing mail server, and the SMTP port<\/b><span style=\"font-weight: 400;\">, as we&#8217;ll need to add them during the next step.<\/span><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"796\" height=\"470\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/2-4.png\" alt=\"How to Send WordPress Emails via SMTP, Configuring WordPress to Use SMTP Without a Plugin 2\" class=\"wp-image-4657\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/2-4.png 796w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/2-4-300x177.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/2-4-768x453.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>\n\n\n<p><span style=\"font-weight: 400;\">If you&#8217;re using a third-party email provider, they should be able to give you the details.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Before we continue, we should probably point out that we&#8217;ll now make changes to wp-config.php \u2013 WP&#8217;s primary configuration file. It might not be a bad idea to <\/span><b>back it up just in case<\/b><span style=\"font-weight: 400;\"> (you can download it to your local computer or simply copy it to another folder on your hosting account).<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">The wp-config file is located in your site&#8217;s document root folder (if you host it under the account&#8217;s primary domain, it should be in <\/span><b>public_html<\/b><span style=\"font-weight: 400;\">). You can use an <\/span><a href=\"https:\/\/www.scalahosting.com\/kb\/how-to-setup-ftp-using-filezilla\/\"><b>FTP client<\/b><\/a><b> to download it<\/b><span style=\"font-weight: 400;\">, edit it locally, and then re-upload it, and if you&#8217;re comfortable working with the command line, <\/span><b>you can also modify it using SSH.<\/b><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">However, most people will find it more convenient to use the <\/span><b>web hosting control panel&#8217;s File Manager and edit the file <\/b><span style=\"font-weight: 400;\">on the spot through the browser.<\/span><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"310\" height=\"706\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/3-4.png\" alt=\"How to Send WordPress Emails via SMTP, Configuring WordPress to Use SMTP Without a Plugin 3\" class=\"wp-image-4658\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/3-4.png 310w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/3-4-132x300.png 132w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>\n\n\n<p><span style=\"font-weight: 400;\">Open the file (by right-clicking and selecting <\/span><b>Edit<\/b><span style=\"font-weight: 400;\">), locate the line that says &#8220;<\/span><b><i>\/* That&#8217;s all, stop editing! Happy publishing. *\/<\/i><\/b><span style=\"font-weight: 400;\">&#8220;, and add the following snippet:<\/span><\/p>\n\n\n\n<p class=\"alert-orange\"><strong>\/\/ SMTP email settings<br>define( &#8216;SMTP_USER&#8217;,   &#8216;[your email address]&#8217; );<br>define( &#8216;SMTP_password&#8217;,   &#8216;[your email inbox password]&#8217; );<br>define( &#8216;SMTP_server&#8217;, &#8216;[the outgoing or SMTP server]&#8217; );<br>define( &#8216;SMTP_FROM&#8217;,   &#8216;[your email address]&#8217; );<br>define( &#8216;SMTP_NAME&#8217;,   &#8216;[the name that will appear in the &#8220;from&#8221; field]&#8217; );<br>define( &#8216;SMTP_PORT&#8217;, &#8216;[the SMTP port]&#8217; );<br>define( &#8216;SMTP_SECURE&#8217;, &#8216;tls&#8217; );<br>define( &#8216;SMTP_AUTH&#8217;, true );<br>define( &#8216;SMTP_DEBUG&#8217;, 0 );\u00a0<\/strong><\/p>\n\n\n\n<p><b>Make sure you enter your own SMTP details in the appropriate placeholders. Here&#8217;s what the file looks like in our case:<\/b><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"439\" height=\"238\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/4-4.png\" alt=\"How to Send WordPress Emails via SMTP, Configuring WordPress to Use SMTP Without a Plugin 4\" class=\"wp-image-4659\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/4-4.png 439w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/4-4-300x163.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>\n\n\n<p><span style=\"font-weight: 400;\">Don&#8217;t forget to save your changes before moving on.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">We&#8217;re putting all this information in the <\/span><b>wp-config.php<\/b><span style=\"font-weight: 400;\"> file for security reasons. The file that is actually going to use it is called <\/span><i><span style=\"font-weight: 400;\">functions.php<\/span><\/i><span style=\"font-weight: 400;\">, and it&#8217;s located in your theme folder.&nbsp;<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">The problem with editing the <\/span><i><span style=\"font-weight: 400;\">functions.php<\/span><\/i><span style=\"font-weight: 400;\"> file is that your modifications will be lost as soon as you update your theme. That&#8217;s why it&#8217;s a good idea to <\/span><a href=\"https:\/\/www.scalahosting.com\/kb\/how-to-customize-your-wordpress-theme\/\"><b>create a child theme<\/b><\/a><span style=\"font-weight: 400;\"> first and modify its functions file instead.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">When you&#8217;re ready, you can use the File Manager to navigate to <\/span><b><i>wp-content\/themes\/[the name of your theme]<\/i><\/b><span style=\"font-weight: 400;\"> or access the file via the <\/span><b>Appearance &gt; Theme File Editor <\/b><span style=\"font-weight: 400;\">menu in the WP dashboard.<\/span><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"339\" height=\"185\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/5-3.png\" alt=\"How to Send WordPress Emails via SMTP, Configuring WordPress to Use SMTP Without a Plugin 5\" class=\"wp-image-4660\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/5-3.png 339w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/5-3-300x164.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>\n\n\n<p><span style=\"font-weight: 400;\">Make sure you&#8217;re editing the correct theme, and pick the <\/span><b>Theme Functions <\/b><span style=\"font-weight: 400;\">file from the menu on the right.<\/span><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"375\" height=\"774\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/6-3.png\" alt=\"How to Send WordPress Emails via SMTP, Configuring WordPress to Use SMTP Without a Plugin 6\" class=\"wp-image-4661\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/6-3.png 375w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/6-3-145x300.png 145w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>\n\n\n<p><span style=\"font-weight: 400;\">Scroll down to the bottom of the file and add the following snippet.<\/span><\/p>\n\n\n\n<p class=\"alert-orange\"><strong>add_action( &#8216;phpmailer_init&#8217;, &#8216;my_phpmailer_smtp&#8217; );<br>function my_phpmailer_smtp( $phpmailer ) {<br>$phpmailer->isSMTP();<br>$phpmailer->Host = SMTP_server;<br>$phpmailer->SMTPAuth = SMTP_AUTH;<br>$phpmailer->Port = SMTP_PORT;<br>$phpmailer->Username = SMTP_username;<br>$phpmailer->Password = SMTP_password;<br>$phpmailer->SMTPSecure = SMTP_SECURE;<br>$phpmailer->From = SMTP_FROM;<br>$phpmailer->FromName = SMTP_NAME;<br>}<\/strong><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">The code above calls the <\/span><b>PHPMailer library<\/b><span style=\"font-weight: 400;\"> and configures it to work with the SMTP settings you added to the wp-config.php file.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">After you save the changes to the theme function file, <\/span><b>WordPress will be configured to work with your SMTP server.<\/b><b><\/b><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Configuring WordPress to Use SMTP With a Plugin<\/b><b><\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">If all this sounds too complicated for you, you can opt for the more user-friendly method and use a plugin to dispatch WordPress emails through SMTP. There&#8217;s certainly no shortage of options.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">In fact, searching for &#8220;SMTP&#8221; in the<\/span> <a href=\"https:\/\/wordpress.org\/plugins\/\"><b>official WordPress repository<\/b><\/a><span style=\"font-weight: 400;\"> returns quite a few results. It&#8217;s up to you to have a good look at them and decide which one fits your requirements.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s easy to overlook important things when working on a brand new online project. For example, when you&#8217;re building your new WordPress site, you may focus all your attention on getting the content and the design right only to forget about WP&#8217;s inherent email deliverability issues. Because of them, critical messages like registration confirmation forms [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":5401,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[26],"tags":[],"class_list":["post-4655","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-email-hosting"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/4655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/comments?post=4655"}],"version-history":[{"count":8,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/4655\/revisions"}],"predecessor-version":[{"id":5779,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/4655\/revisions\/5779"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/media\/5401"}],"wp:attachment":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/media?parent=4655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/categories?post=4655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/tags?post=4655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}