{"id":3026,"date":"2013-11-08T19:39:33","date_gmt":"2013-11-09T00:39:33","guid":{"rendered":"http:\/\/www.lonhosford.com\/lonblog\/?p=3026"},"modified":"2015-07-31T18:25:48","modified_gmt":"2015-07-31T23:25:48","slug":"how-to-send-email-from-xampp-using-localhost-on-a-mac-and-your-gmail-account","status":"publish","type":"post","link":"https:\/\/www.lonhosford.com\/lonblog\/2013\/11\/08\/how-to-send-email-from-xampp-using-localhost-on-a-mac-and-your-gmail-account\/","title":{"rendered":"How to Send Email From XAMPP using localhost on a Mac and your Gmail Account"},"content":{"rendered":"<a href='https:\/\/www.lonhosford.com\/lonblog?bha=true&#038;user=alhecommerce&#038;id=shortcode\/LonBlogGeneral'><img class='none' src='https:\/\/img.bluehost.com\/\/468x60\/bh_468x60_01.gif' \/><\/a>\n<div id=\"fb-root\"><\/div>\n<p><script src=\"https:\/\/connect.facebook.net\/en_US\/all.js#appId=105467682877384&amp;xfbml=1\"><\/script><fb:like href=\"https:\/\/www.lonhosford.com\/lonblog\/2013\/11\/08\/how-to-send-email-from-xampp-using-localhost-on-a-mac-and-your-gmail-account\/\" send=\"true\" width=\"450\" show_faces=\"true\" font=\"\"><\/fb:like><!-- Place this tag where you want the +1 button to render --><br \/>\n<g:plusone annotation=\"inline\"><\/g:plusone><\/p>\n<p>By Lon Hosford<\/p>\n<p>This is sample code for using SMTP and your Google GMail account with XAMPP installed on a Mac and PHPMailer.<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.lonhosford.com\/lonblog\/wp-content\/uploads\/2013\/11\/xampp_in_envelope_150x96-300x192.jpg\" alt=\"xampp_in_envelope_150x96\" width=\"300\" height=\"192\" class=\"alignleft size-medium wp-image-3117\" srcset=\"https:\/\/www.lonhosford.com\/lonblog\/wp-content\/uploads\/2013\/11\/xampp_in_envelope_150x96-300x192.jpg 300w, https:\/\/www.lonhosford.com\/lonblog\/wp-content\/uploads\/2013\/11\/xampp_in_envelope_150x96.jpg 500w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><br \/>\nOften you want to send mail from your web site to yourself from a user form or even to others. But you may be using XAMPP as a local host and want to test that without having to upload to a public server. This script shows how you can do that with PHPMailer. <\/p>\n<p>Step 1: Install <a title=\"XAMPP MacOS\" href=\"http:\/\/www.apachefriends.org\/en\/xampp-macosx.html\">XAMPP MacOS<\/a> <\/p>\n<p>Step 2: Download <a title=\"PHPMailer\" href=\"https:\/\/github.com\/PHPMailer\/PHPMailer\" target=\"_blank\">PHPMailer<\/a> [ad name=&#8221;Google Adsense&#8221;] <\/p>\n<p>Step 3: Create a testing php file shown below. Be sure you have the correct paths to class.phpmailer.php and class.smtp.php on lines 3 and 4 that you downloaded with PHPMailer.<\/p>\n<pre class=\"brush: php; collapse: false; title: ; notranslate\" title=\"\">\r\n&lt;!--?php \r\ninclude(&quot;class.phpmailer.php&quot;); \r\ninclude(&quot;class.smtp.php&quot;); \r\nfunction test_gmail_smtp_basic() {\r\n \t\/\/ Uncomment as needed for debugging\r\n \t\/\/error_reporting(E_ALL);\r\n  \t\/\/error_reporting(E_STRICT);\r\n \t\/\/ Set as needed\r\n\tdate_default_timezone_set('America\/New_York');\r\n\t$mail = new PHPMailer(); \r\n\t\/\/ Optionally get email body from external file\r\n \t$body = file_get_contents('contents.html');\r\n \t$body = eregi_replace(&quot;&#x5B;\\]&quot;,'',$body);\r\n  \t$mail-&gt;IsSMTP();                            \/\/ telling the class to use SMTP\r\n\t$mail-&gt;Host       = &quot;smtp.gmail.com&quot;;       \/\/ SMTP server\r\n\t$mail-&gt;SMTPDebug  = 2;                      \/\/ enables SMTP debug information (for testing)\r\n                                                    \/\/ 0 default no debugging messages\r\n                                                    \/\/ 1 = errors and messages\r\n                                                    \/\/ 2 = messages only\r\n\t$mail-&gt;SMTPAuth   = true;                   \/\/ enable SMTP authentication\r\n\t\/\/$mail-&gt;SMTPSecure = 'ssl';                \/\/ Not supported\r\n\t$mail-&gt;SMTPSecure = 'tls';                  \/\/ Supported\r\n\t$mail-&gt;Host       = &quot;smtp.gmail.com&quot;;       \/\/ sets the SMTP server\r\n\t$mail-&gt;Port       = 587;                    \/\/ set the SMTP port for the GMAIL server\r\n\t$mail-&gt;Username   = &quot;me@gmail.com&quot;;         \/\/ SMTP account username (how you login at gmail)\r\n\t$mail-&gt;Password   = &quot;mygmailpassword&quot;;      \/\/ SMTP account password (how you login at gmail)\r\n\r\n\t$mail-&gt;setFrom('mememe@gmail.com', 'Joe Dirt');\r\n\r\n\t$mail-&gt;addReplyTo('mememe@gmail.com', 'Joe Dirt&quot;);\r\n\r\n\t$mail-&gt;Subject    = &quot;PHPMailer Test Subject via smtp, basic with authentication&quot;;\r\n\r\n\t$mail-&gt;AltBody    = &quot;To view the message, please use an HTML compatible email viewer!&quot;; \/\/ optional, comment out and test\r\n\r\n\t$mail-&gt;msgHTML($body);\r\n\r\n\t$address = &quot;someone-else@their-email-domain.com&quot;;\r\n\t$mail-&gt;addAddress($address, &quot;Miss Piggy&quot;);\r\n\t\/\/ if you have attachments\r\n\t$mail-&gt;addAttachment(&quot;phpmailer.gif&quot;);      \/\/ attachment \r\n\t$mail-&gt;addAttachment(&quot;phpmailer_mini.gif&quot;); \/\/ attachment\r\n\r\n\tif(!$mail-&gt;Send()) {\r\n\t  echo &quot;Mailer Error: &quot; . $mail-&gt;ErrorInfo;\r\n\t} else {\r\n\t  echo &quot;Message sent!&quot;;\r\n\t}\r\n}\r\n\/\/ Test the connection\r\ntest_gmail_smtp_basic();\r\n?&gt;\r\n<\/pre>\n<p>What you may find is an issue with many examples heretofore is that SMTPSecure shown on line 25 needs to be TLS (Transport Layer Security) instead of SSL (Secure Sockets Layer). The other item is the port number is 587 as you see on line 29. You can disable line 29 once you have this fully debugged. Use with care.\u00a0<\/p>\n<p>These images come with PHPMailer and are included here for your convenience. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"phpmailer.gif\" src=\"https:\/\/www.lonhosford.com\/images\/xampp\/phpmailer.gif\" width=\"170\" height=\"45\" \/> <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"phpmailer.gif\" src=\"https:\/\/www.lonhosford.com\/images\/xampp\/phpmailer_mini.gif\" width=\"79\" height=\"59\" \/> <\/p>\n<p>Optional external html file for the body content. See line 12 in the code above.<\/p>\n<pre class=\"brush: xml; collapse: true; light: false; title: ; toolbar: true; notranslate\" title=\"\">&lt;body style=&quot;margin: 10px;&quot;&gt;\r\n&lt;div style=&quot;width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;&quot;&gt;\r\n&lt;div align=&quot;center&quot;&gt;&lt;img style=&quot;height: 90px; width: 340px;&quot; alt=&quot;&quot; src=&quot;phpmailer.gif&quot; \/&gt;&lt;\/div&gt;&lt;br&gt;\r\n&lt;br&gt;\r\n&amp;nbsp;This is a test of PHPMailer.&lt;br&gt;\r\n&lt;br&gt;\r\nThis particular example uses &lt;strong&gt;HTML&lt;\/strong&gt;, with a &lt;div&gt; tag and inline&lt;br&gt;\r\nstyles.&lt;br&gt;\r\n&lt;br&gt;\r\nAlso note the use of the PHPMailer logo above with no specific code to handle\r\nincluding it.&lt;br \/&gt;\r\nIncluded are two attachments:&lt;br \/&gt;\r\nphpmailer.gif is an attachment and used inline as a graphic (above)&lt;br \/&gt;\r\nphpmailer_mini.gif is an attachment&lt;br \/&gt;\r\n&lt;br \/&gt;\r\nPHPMailer:&lt;br \/&gt;\r\nAuthor: Lon Hosford (somebody@no.net)\r\n&lt;\/div&gt;\r\n&lt;\/body&gt;\r\n<\/pre>\n<p>[ad name=&#8221;Google Adsense&#8221;]<br \/>\n<g:plusone annotation=\"inline\"><\/g:plusone><\/p>\n<div id=\"fb-root\"><\/div>\n<p><script src=\"https:\/\/connect.facebook.net\/en_US\/all.js#appId=105467682877384&amp;xfbml=1\"><\/script><fb:like href=\"https:\/\/www.lonhosford.com\/lonblog\/2013\/11\/08\/how-to-send-email-from-xampp-using-localhost-on-a-mac-and-your-gmail-account\/\" send=\"true\" width=\"450\" show_faces=\"true\" font=\"\"><\/fb:like><\/p>\n<div id=\"fb-root\"><\/div>\n<p><script src=\"https:\/\/connect.facebook.net\/en_US\/all.js#xfbml=1\"><\/script><fb:comments href=\"https:\/\/www.lonhosford.com\/lonblog\/2013\/11\/08\/how-to-send-email-from-xampp-using-localhost-on-a-mac-and-your-gmail-account\/\" num_posts=\"3\" width=\"500\"><\/fb:comments><\/p>\n<p><!-- Place this render call where appropriate --><br \/>\n<script type=\"text\/javascript\">\n  (function() {\n    var po = document.createElement('script'); po.type = 'text\/javascript'; po.async = true;\n    po.src = 'https:\/\/apis.google.com\/js\/plusone.js';\n    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);\n  })();\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Lon Hosford This is sample code for using SMTP and your Google GMail account with XAMPP installed on a Mac and PHPMailer. Often you want to send mail from your web site to yourself from a user form or even to others. But you may be using XAMPP as a local host and want [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3117,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[57,84],"class_list":["post-3026","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general","tag-php-2","tag-sendmail"],"_links":{"self":[{"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/posts\/3026","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/comments?post=3026"}],"version-history":[{"count":47,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/posts\/3026\/revisions"}],"predecessor-version":[{"id":3656,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/posts\/3026\/revisions\/3656"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/media\/3117"}],"wp:attachment":[{"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/media?parent=3026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/categories?post=3026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/tags?post=3026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}