{"id":2521,"date":"2024-02-12T07:15:30","date_gmt":"2024-02-12T13:15:30","guid":{"rendered":"https:\/\/promincproductions.com\/blog\/?p=2521"},"modified":"2024-02-12T07:15:31","modified_gmt":"2024-02-12T13:15:31","slug":"xampp-configure-email-to-send-through-gmail","status":"publish","type":"post","link":"https:\/\/promincproductions.com\/blog\/xampp-configure-email-to-send-through-gmail\/","title":{"rendered":"XAMPP Configure Email to Send Through Gmail"},"content":{"rendered":"<p>XAMPP is a great tool for setting up a webserver quickly and getting a PHP based site up and running.  But getting PHP to reliably send email through can be a bit of an issue &#8211; especially for keeping the emails out of junk folders.  Thankfully Gmail can be configured to send the emails easily and are a huge help in keeping emails out of the recipients spam folder. <\/p>\n\n\n<div class=\"wp-block-image is-resized\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"600\" height=\"600\" src=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/xampp-send-email-through-gmail.png\" alt=\"Use Gmail to send email in XAMPP\" class=\"wp-image-2618\" title=\"Use Gmail to send email in XAMPP\" srcset=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/xampp-send-email-through-gmail.png 600w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/xampp-send-email-through-gmail-500x500.png 500w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/xampp-send-email-through-gmail-150x150.png 150w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/xampp-send-email-through-gmail-450x450.png 450w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">Gmail Password Configuration<\/h2>\n\n\n\n<p>Gmail <s>has<\/s> had two methods for connecting PHP applications to Gmail.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Less Secure Apps<\/li>\n\n\n\n<li>App Passwords<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Less Secure Apps<\/h3>\n\n\n\n<p>This method used an account username and password to connect PHP application or XAMPP <code>sendmail<\/code> to Gmail.  This is the same username and password used to login to the web interface and email clients.  Google has deprecated this connection method as of May 30th, 2022.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>To help keep your account secure, starting&nbsp;<strong>May 30, 2022<\/strong>, \u200b\u200bGoogle will no longer support the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password.<\/p>\n<cite>Google [<a href=\"https:\/\/support.google.com\/accounts\/answer\/6010255?hl=en\" target=\"_blank\" rel=\"nofollow noopener\" data-lasso-id=\"979\">https:\/\/support.google.com\/accounts\/answer\/6010255?hl=en<\/a>]<\/cite><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">App Password<\/h3>\n\n\n\n<p>App Passwords are designed to be additional username \/ password sets for specific uses.  It is best practice to make an App Password for each application.  This allows for clear segregation of connections.  One <em>caveat<\/em> to App Passwords is that the Gmail account must have <a href=\"https:\/\/support.google.com\/accounts\/answer\/185839\" target=\"_blank\" rel=\"nofollow noopener\" data-lasso-id=\"980\">2-Step (or 2 factor) Authentication<\/a> enabled.  But, in this day in age, that is best practice anyway so this shouldn&#8217;t be a big hurdle.<\/p>\n\n\n\n<p>Gmail App Password Reference: <a href=\"https:\/\/support.google.com\/accounts\/answer\/185833\" target=\"_blank\" rel=\"nofollow noopener\" data-lasso-id=\"981\">https:\/\/support.google.com\/accounts\/answer\/185833<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Gmail Account Setup<\/h2>\n\n\n\n<p>Before XAMPP can be configured, the Gmail account needs to be setup correctly.  As noted above, the <strong>Less Secure Apps<\/strong> method is deprecated by Gmail and thus this tutorial will <em>only<\/em> use the <strong>App Password<\/strong> method.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Confirm <strong>2-Step Authentication<\/strong> is Enabled\n<ul class=\"wp-block-list\">\n<li>Go to the <strong>Gmail Account Security<\/strong> page when logged into the Gmail account: <a href=\"https:\/\/myaccount.google.com\/security\" target=\"_blank\" rel=\"nofollow noopener\" data-lasso-id=\"982\">https:\/\/myaccount.google.com\/security<\/a><\/li>\n\n\n\n<li>Look for the <strong>Signing in to Google<\/strong> section.\n<ul class=\"wp-block-list\">\n<li>If <strong>2-Step Authentication<\/strong> is enabled, it will say <strong>On<\/strong>.<\/li>\n\n\n\n<li>If <strong>2-Step Authentication<\/strong> is <em>NOT<\/em> enabled, follow Googles instructions to enable.  <a href=\"https:\/\/support.google.com\/accounts\/answer\/185839\" target=\"_blank\" rel=\"nofollow noopener\" data-lasso-id=\"983\">https:\/\/support.google.com\/accounts\/answer\/185839<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"396\" src=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-28-1024x396.png\" alt=\"Google Account Security Password Configuration Page\" class=\"wp-image-2615\" style=\"width:561px;height:217px\" srcset=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-28-1024x396.png 1024w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-28-500x194.png 500w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-28-768x297.png 768w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-28-150x58.png 150w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-28-600x232.png 600w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-28-450x174.png 450w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-28.png 1077w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li>Create an <strong>App Password<\/strong>.  Google documents this process well, and it may be subject to change, so follow their directions here: <a href=\"https:\/\/support.google.com\/accounts\/answer\/185833\" target=\"_blank\" rel=\"nofollow noopener\" data-lasso-id=\"984\">https:\/\/support.google.com\/accounts\/answer\/185833<\/a>\n<ul class=\"wp-block-list\">\n<li>When creating the password, select the <strong>Other (Custom name)<\/strong> option from the <strong>Select app<\/strong> dropdown.  It then prompts for a name &#8211; enter a <em>logical<\/em> name that explains what this password will be used for.<\/li>\n\n\n\n<li>Click the <strong>Generate<\/strong> button and Google will provide the App Password.  Save this auto-generated password in a safe place.  This is the one time that Google will show the password &#8211; it can not be retrieved again after this and thus a new App Password will need to be generated if it is ever lost.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" width=\"871\" height=\"812\" src=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-29.png\" alt=\"App type dropdown when creating a Gmail App Password\" class=\"wp-image-2616\" style=\"width:603px;height:562px\" title=\"App type dropdown when creating a Gmail App Password\" srcset=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-29.png 871w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-29-500x466.png 500w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-29-768x716.png 768w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-29-150x140.png 150w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-29-600x559.png 600w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-29-450x420.png 450w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-29-644x600.png 644w\" sizes=\"(max-width: 871px) 100vw, 871px\" \/><figcaption class=\"wp-element-caption\">Select <em>Other (Custom name)<\/em>for the app type from the dropdown when creating an App Password for XAMPP<\/figcaption><\/figure>\n<\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"832\" height=\"208\" src=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-30.png\" alt=\"App Password name input box\" class=\"wp-image-2617\" title=\"App Password name input box\" srcset=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-30.png 832w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-30-500x125.png 500w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-30-768x192.png 768w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-30-150x38.png 150w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-30-600x150.png 600w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/image-30-450x113.png 450w\" sizes=\"(max-width: 832px) 100vw, 832px\" \/><figcaption class=\"wp-element-caption\">Set a recognizable name for the App Password<\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">Configure XAMPP to Send Email through Gmail App Password<\/h2>\n\n\n\n<p>Now that the Gmail App Password has been obtained, XAMPP needs to be configured.  XAMPP is pre-packaged with <a href=\"https:\/\/www.proofpoint.com\/us\/products\/email-protection\/open-source-email-solution\" target=\"_blank\" rel=\"nofollow noopener\" data-lasso-id=\"985\">sendmail<\/a> &#8211; an application that will handle the email sending function from PHP.<\/p>\n\n\n\n<p>XAMPP has a sendmail configuration file that needs to be edited, however there isn&#8217;t an easy button to find it in the XAMPP Control Panel like the other configuration files.  To find the configuration file, go to the installation directory of XAMPP in Windows Explorer.  There is a button in the XAMPP Control Panel on the right that says <strong>Explorer<\/strong> that will open it, else it&#8217;s typically installed at <code>C:\\xampp<\/code>.  Then go into the <em>sendmail<\/em> directory and open file <code>sendmail.ini<\/code> in a text editor &#8211; the default is Notepad.<\/p>\n\n\n\n<p>A quick note about <code>.ini<\/code> files.  A colon character means that any text after it is a comment and will be <em>ignored<\/em> by the application.  These comments are left there for humans to read.  These comments are great to keep so it&#8217;s easy to reference what the sample configuration was.  It&#8217;s best practice to copy the line, create a new line and remove the colon from the beginning of the new line with the modified configuration.<\/p>\n\n\n\n<p>Look for line <code>; smtp_server=mail.mydomain.com<\/code>  Just below this line, add configuration for the XAMPP application.  For all Gmail configuration the server is <code>smtp.gmail.com<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>; smtp_server=mail.mydomain.com\nsmtp_server=smtp.gmail.com<\/code><\/pre>\n\n\n\n<p>Next look for line <code>; smtp_port=25<\/code> and configure the standard Gmail SMTP port of <code>587<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>; smtp_port=25\nsmtp_port=587<\/code><\/pre>\n\n\n\n<p>Lastly look for lines:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>; auth_username=\n; auth_password=\n<\/code><\/pre>\n\n\n\n<p>Here is where the Gmail accounts email address and the App Password that was just generated will be used.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>; auth_username=\n; auth_password=\n\nauth_username=youremailaddress@gmail.com\nauth_password=app-password-from-gmail-configuration-steps-above<\/code><\/pre>\n\n\n\n<p>Save the <code>sendmail.ini<\/code> file to lock in the configuration.<\/p>\n\n\n\n<p>In the main XAMPP Control Panel, restart&nbsp;<strong>Apache<\/strong>&nbsp;by clicking the&nbsp;<strong>Stop<\/strong>&nbsp;and then&nbsp;<strong>Start<\/strong>&nbsp;button.<\/p>\n\n\n\n<p>Now XAMPP and sendmail are configured to send email through Gmail.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Logging<\/h2>\n\n\n\n<p>Sendmail can be configured to write some log data which will be useful to know what is occurring with your mail sends.  In the <code>sendmail.ini<\/code> file uncomment by removing the leading <code>;<\/code> (or add) these lines and save the file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>error_logfile=error.log\n\ndebug_logfile=debug.log\n<\/code><\/pre>\n\n\n\n<p>The log files will be located in the XAMPP Sendmail directory &#8211; typically <code>C:\\xampp\\sendmail<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">debug.log<\/h3>\n\n\n\n<p>The <code>debug.log<\/code> file will be verbose as it logs the email message header information, subject line, full body of the email, etc.  As the log type suggests &#8211; this should be used for debugging and typically should be disabled on a production environment.  Given that it logs the full email body this could lead to a security risk as well as sensitive data may be logged and stored in plain text on the server (depending on the contents of the emails sent of course).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">error.log<\/h3>\n\n\n\n<p>The <code>error.log<\/code> file is likely wise to run on production environments as it&#8217;ll indicate critical issues like miss configurations, invalid credentials, etc. and would be very important to know when errors of these types occur.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Test PHP Script<\/h2>\n\n\n\n<p>This sample PHP script will loop through recipients to test sending email.  Save this file within the XAMPP <code>htdocs<\/code> directory and call it by URL in the browser to test if sendmail with XAMPP will send the emails.  If the configuration is setup correctly, the email should be received in the recipients inboxes momentarily.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$recipients = &#091;'recipient1@example.com','recipient2@example.com'];\n\n$subject = 'Test Email from XAMPP';\n$fromName = 'Test Senders Name';\n$fromEmail = 'sender@example.com';\n\n$message  = '&lt;html&gt;&lt;body&gt;';\n$message .= '&lt;p&gt;This is a test email.&lt;\/p&gt;';\n$message .= '&lt;\/body&gt;&lt;\/html&gt;';\n\n$NL = \"\\r\\n\";\n\necho \"&lt;h3&gt;Emails Sent To:&lt;\/h3&gt;\";\necho \"&lt;ul&gt;\";\nfor ($c=0; $c &lt; count($recipients); $c++)\n{\n\t$to = $recipients&#091;$c];\n\n\t$headers = \"\";\n\tif( strpos( $message, '&lt;html' ) !== false ) {\n\t\t$headers .= \"MIME-Version: 1.0\".$NL;\n\t\t$headers .= \"Content-type:text\/html;charset=UTF-8\".$NL;\n\t}\n\n\t$headers  .= \"From: \" . $fromName . \" &lt;\" . $fromEmail . \"&gt;\" . $NL;\n\t$headers  .= \"Reply-To: \" . $fromName . \" &lt;\" . $fromEmail . \"&gt;\" . $NL;\n\n\tif( mail( $to, $subject, $message, $headers ) ) {\n\t\techo \"&lt;li&gt;&lt;b&gt;\" . $to . \"&lt;\/b&gt; (&lt;i&gt;success&lt;\/i&gt;)&lt;\/li&gt;\";\n\t} else {\n\t\techo \"&lt;li&gt;&lt;b&gt;\" . $to . \"&lt;\/b&gt; (&lt;i&gt;failed&lt;\/i&gt;)&lt;\/li&gt;\";\n\t}\n}\necho \"&lt;\/ul&gt;\";<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sendmail-via-gmail\">Troubleshooting<\/h2>\n\n\n\n<p>If the email isn&#8217;t being received, there are a few things to check and consider.<\/p>\n\n\n\n<p>XAMPP and Apache keep an error log that often has clues as to what isn&#8217;t working as expected.  This file is typically located at <code>C:\\xampp\\apache\\logs\\error.log<\/code> and can be viewed in a standard text editor like Notepad.  A log viewer program like <a href=\"http:\/\/snakenest.com\/snaketail\/\" target=\"_blank\" rel=\"nofollow noopener\" data-lasso-id=\"986\">SnakeTail<\/a> is great for watching log files.  As new entries get added to the log file it will adjust and scroll the view.  But the log file is a great first place to start troubleshooting any issues.<\/p>\n\n\n\n<p>The other common issue to consider is if a firewall is blocking the mail from being sent.  Windows has a firewall as well as the router and other network hardware on the network.  Ensure that outbound traffic through port 587 is allowed.<\/p>","protected":false},"excerpt":{"rendered":"<p>XAMPP is a great tool for setting up a webserver quickly and getting a PHP based site up [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2618,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wprm-recipe-roundup-name":"","wprm-recipe-roundup-description":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[5],"tags":[351],"class_list":["post-2521","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-website-development","tag-xampp"],"jetpack_featured_media_url":"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/03\/xampp-send-email-through-gmail.png","jetpack_shortlink":"https:\/\/wp.me\/p4BbcR-EF","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/2521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/comments?post=2521"}],"version-history":[{"count":12,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/2521\/revisions"}],"predecessor-version":[{"id":3540,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/2521\/revisions\/3540"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/media\/2618"}],"wp:attachment":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/media?parent=2521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/categories?post=2521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/tags?post=2521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}