{"id":1288,"date":"2016-02-25T17:12:48","date_gmt":"2016-02-25T17:12:48","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=1288"},"modified":"2022-08-03T15:36:40","modified_gmt":"2022-08-03T15:36:40","slug":"how-to-send-email-from-localhost-in-php","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/","title":{"rendered":"How to Send Email from Localhost in PHP"},"content":{"rendered":"<p>Localhost is used as a development server to develop a web application. All the functionality of the web application is tested on the localhost server before moving it to the production server. But, the problem arises when email functionality needs to be tested on the localhost server. Generally, the email sending feature is not working with the PHP built-in functions in localhost.<\/p>\n<p>If the web application is built with PHP, the mail() function is used to <a href=\"https:\/\/www.codexworld.com\/send-beautiful-html-email-using-php\/\">send email from the script using PHP<\/a>. But the <b>PHP mail()<\/b> function will not work in localhost. In this tutorial, we&#8217;ll show how you can <b>send email from localhost in PHP<\/b>. Using this example script you can send email from any localhost server (XAMPP, WAMP, or any others) using PHP.<\/p>\n<p>We will use the PHPMailer library to send emails from localhost using PHP. The PHPMailer library provides the easiest way to send an email from localhost with an SMTP server using PHP. Not only the text email, but you can also <b>send HTML email from localhost in PHP<\/b> using PHPMailer.<\/p>\n<p><b>SMTP Server Credentials:<\/b><br \/>\nBefore getting started create an email account on your server and collect the SMTP credentials (Host, Port, Username, Password, etc.) that will require to be specified in the code later.<\/p>\n<h2>Send Email from Localhost with PHP<\/h2>\n<p>The following code snippet will send HTML email from localhost using PHPMailer.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>Include the PHPMailer library and create an instance of this class.<\/li>\n<li>Set SMTP credentials (host, username, password, and port).<\/li>\n<li>Specify sender name and email (<code>$mail->setFrom<\/code>).<\/li>\n<li>Set recipient email address (<code>$mail->addAddress<\/code>).<\/li>\n<li>Set email subject (<code>$mail->Subject<\/code>).<\/li>\n<li>Set the body content of the email (<code>$mail->Body<\/code>).<\/li>\n<li>Use the <code>send()<\/code> method of PHPMailer class to send an email.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Import&nbsp;PHPMailer&nbsp;classes&nbsp;into&nbsp;the&nbsp;global&nbsp;namespace <br \/><\/span><span style=\"color: #007700\">use&nbsp;<\/span><span style=\"color: #0000BB\">PHPMailer<\/span><span style=\"color: #007700\">\\<\/span><span style=\"color: #0000BB\">PHPMailer<\/span><span style=\"color: #007700\">\\<\/span><span style=\"color: #0000BB\">PHPMailer<\/span><span style=\"color: #007700\">; <br \/>use&nbsp;<\/span><span style=\"color: #0000BB\">PHPMailer<\/span><span style=\"color: #007700\">\\<\/span><span style=\"color: #0000BB\">PHPMailer<\/span><span style=\"color: #007700\">\\<\/span><span style=\"color: #0000BB\">SMTP<\/span><span style=\"color: #007700\">; <br \/>use&nbsp;<\/span><span style=\"color: #0000BB\">PHPMailer<\/span><span style=\"color: #007700\">\\<\/span><span style=\"color: #0000BB\">PHPMailer<\/span><span style=\"color: #007700\">\\<\/span><span style=\"color: #0000BB\">Exception<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;library&nbsp;files <br \/><\/span><span style=\"color: #007700\">require&nbsp;<\/span><span style=\"color: #DD0000\">'PHPMailer\/Exception.php'<\/span><span style=\"color: #007700\">; <br \/>require&nbsp;<\/span><span style=\"color: #DD0000\">'PHPMailer\/PHPMailer.php'<\/span><span style=\"color: #007700\">; <br \/>require&nbsp;<\/span><span style=\"color: #DD0000\">'PHPMailer\/SMTP.php'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Create&nbsp;an&nbsp;instance;&nbsp;Pass&nbsp;`true`&nbsp;to&nbsp;enable&nbsp;exceptions <br \/><\/span><span style=\"color: #0000BB\">$mail&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">PHPMailer<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Server&nbsp;settings <br \/>\/\/$mail-&gt;SMTPDebug&nbsp;=&nbsp;SMTP::DEBUG_SERVER;&nbsp;&nbsp;&nbsp;&nbsp;\/\/Enable&nbsp;verbose&nbsp;debug&nbsp;output <br \/><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">isSMTP<\/span><span style=\"color: #007700\">();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Set&nbsp;mailer&nbsp;to&nbsp;use&nbsp;SMTP <br \/><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">Host&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'smtp.example.com'<\/span><span style=\"color: #007700\">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Specify&nbsp;main&nbsp;and&nbsp;backup&nbsp;SMTP&nbsp;servers <br \/><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">SMTPAuth&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">true<\/span><span style=\"color: #007700\">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Enable&nbsp;SMTP&nbsp;authentication <br \/><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">Username&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'user@example.com'<\/span><span style=\"color: #007700\">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;SMTP&nbsp;username <br \/><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">Password&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'email_password'<\/span><span style=\"color: #007700\">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;SMTP&nbsp;password <br \/><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">SMTPSecure&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'ssl'<\/span><span style=\"color: #007700\">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Enable&nbsp;TLS&nbsp;encryption,&nbsp;`ssl`&nbsp;also&nbsp;accepted <br \/><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">Port&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">465<\/span><span style=\"color: #007700\">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;TCP&nbsp;port&nbsp;to&nbsp;connect&nbsp;to <br \/> <br \/>\/\/&nbsp;Sender&nbsp;info <br \/><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">setFrom<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'sender@example.com'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'SenderName'<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">addReplyTo<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'reply@example.com'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'SenderName'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Add&nbsp;a&nbsp;recipient <br \/><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">addAddress<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'recipient@example.com'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/$mail-&gt;addCC('cc@example.com'); <br \/>\/\/$mail-&gt;addBCC('bcc@example.com'); <br \/> <br \/>\/\/&nbsp;Set&nbsp;email&nbsp;format&nbsp;to&nbsp;HTML <br \/><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">isHTML<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">true<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Mail&nbsp;subject <br \/><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">Subject&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'Email&nbsp;from&nbsp;Localhost&nbsp;by&nbsp;CodexWorld'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Mail&nbsp;body&nbsp;content <br \/><\/span><span style=\"color: #0000BB\">$bodyContent&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;h1&gt;How&nbsp;to&nbsp;Send&nbsp;Email&nbsp;from&nbsp;Localhost&nbsp;using&nbsp;PHP&nbsp;by&nbsp;CodexWorld&lt;\/h1&gt;'<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$bodyContent&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;p&gt;This&nbsp;HTML&nbsp;email&nbsp;is&nbsp;sent&nbsp;from&nbsp;the&nbsp;localhost&nbsp;server&nbsp;using&nbsp;PHP&nbsp;by&nbsp;&lt;b&gt;CodexWorld&lt;\/b&gt;&lt;\/p&gt;'<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">Body&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$bodyContent<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Send&nbsp;email <br \/><\/span><span style=\"color: #007700\">if(!<\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">send<\/span><span style=\"color: #007700\">())&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #DD0000\">'Message&nbsp;could&nbsp;not&nbsp;be&nbsp;sent.&nbsp;Mailer&nbsp;Error:&nbsp;'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">ErrorInfo<\/span><span style=\"color: #007700\">; <br \/>}&nbsp;else&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #DD0000\">'Message&nbsp;has&nbsp;been&nbsp;sent.'<\/span><span style=\"color: #007700\">; <br \/>}<\/span><\/pre>\n<p><span class=\"note\">Note that:<\/span> If you want to use Gmail as an SMTP server, set your Google email address as SMTP username and password as SMTP password.<\/p>\n<p class=\"seeAlso\"><span><\/span><a href=\"https:\/\/www.codexworld.com\/send-html-email-php-gmail-smtp-phpmailer\/\">Send Email via SMTP Server in PHP using PHPMailer<\/a><\/span><\/p>\n<p>You can send emails with multiple attachments from localhost with PHPMailer. <\/p>\n<ul class=\"bullet_disk_list\">\n<li>Set file path to <b>addAttachment()<\/b> method.<\/li>\n<\/ul>\n<pre><span style=\"color: #FF8000\">\/\/&nbsp;Add&nbsp;attachments<br><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">addAttachment<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'\/var\/tmp\/file.tar.gz'<\/span><span style=\"color: #007700\">);<br><\/span><span style=\"color: #0000BB\">$mail<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">addAttachment<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'\/tmp\/image.jpg'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'new.jpg'<\/span><span style=\"color: #007700\">);&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Optional&nbsp;name<br><\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Localhost is used as a development server to develop a web application. All the functionality of the web application is tested on the localhost server before moving it to the production server. But, the problem <\/p>\n","protected":false},"author":1,"featured_media":5023,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[23,24,144,14,147,146,145],"class_list":["post-1288","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-email","tag-html-email","tag-localhost","tag-php","tag-phpmailer","tag-wamp","tag-xampp","cat-4-id","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Send Email from Localhost in PHP - CodexWorld<\/title>\n<meta name=\"description\" content=\"Send Email from XAMPP or WAMP - Use SMTP server to send email from localhost using PHP. Example code snippet to send HTML email from localhost with PHPMailer and Gmail SMTP in PHP.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Send Email from Localhost in PHP - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"Send Email from XAMPP or WAMP - Use SMTP server to send email from localhost using PHP. Example code snippet to send HTML email from localhost with PHPMailer and Gmail SMTP in PHP.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/\" \/>\n<meta property=\"og:site_name\" content=\"CodexWorld\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:published_time\" content=\"2016-02-25T17:12:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-03T15:36:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/how-to-send-email-from-localhost-server-in-php.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1366\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CodexWorld\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codexworldblog\" \/>\n<meta name=\"twitter:site\" content=\"@codexworldweb\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CodexWorld\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/how-to-send-email-from-localhost-in-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/how-to-send-email-from-localhost-in-php\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"How to Send Email from Localhost in PHP\",\"datePublished\":\"2016-02-25T17:12:48+00:00\",\"dateModified\":\"2022-08-03T15:36:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/how-to-send-email-from-localhost-in-php\\\/\"},\"wordCount\":335,\"commentCount\":50,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/how-to-send-email-from-localhost-in-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/02\\\/how-to-send-email-from-localhost-server-in-php.png\",\"keywords\":[\"Email\",\"HTML Email\",\"Localhost\",\"PHP\",\"PHPMailer\",\"WAMP\",\"XAMPP\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/how-to-send-email-from-localhost-in-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/how-to-send-email-from-localhost-in-php\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/how-to-send-email-from-localhost-in-php\\\/\",\"name\":\"How to Send Email from Localhost in PHP - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/how-to-send-email-from-localhost-in-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/how-to-send-email-from-localhost-in-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/02\\\/how-to-send-email-from-localhost-server-in-php.png\",\"datePublished\":\"2016-02-25T17:12:48+00:00\",\"dateModified\":\"2022-08-03T15:36:40+00:00\",\"description\":\"Send Email from XAMPP or WAMP - Use SMTP server to send email from localhost using PHP. Example code snippet to send HTML email from localhost with PHPMailer and Gmail SMTP in PHP.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/how-to-send-email-from-localhost-in-php\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/how-to-send-email-from-localhost-in-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/how-to-send-email-from-localhost-in-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/02\\\/how-to-send-email-from-localhost-server-in-php.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/02\\\/how-to-send-email-from-localhost-server-in-php.png\",\"width\":1366,\"height\":768,\"caption\":\"how-to-send-email-from-localhost-server-in-php\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/how-to-send-email-from-localhost-in-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Send Email from Localhost in PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"name\":\"CodexWorld\",\"description\":\"Web &amp; Mobile App Development Company\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codexworld.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\",\"name\":\"CodexWorld\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"width\":200,\"height\":19,\"caption\":\"CodexWorld\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldweb\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codexworld\",\"https:\\\/\\\/www.youtube.com\\\/codexworld\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\",\"name\":\"CodexWorld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"caption\":\"CodexWorld\"},\"description\":\"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.\",\"sameAs\":[\"http:\\\/\\\/www.codexworld.com\",\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldblog\"],\"url\":\"https:\\\/\\\/www.codexworld.com\\\/author\\\/nitya192265\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Send Email from Localhost in PHP - CodexWorld","description":"Send Email from XAMPP or WAMP - Use SMTP server to send email from localhost using PHP. Example code snippet to send HTML email from localhost with PHPMailer and Gmail SMTP in PHP.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/","og_locale":"en_US","og_type":"article","og_title":"How to Send Email from Localhost in PHP - CodexWorld","og_description":"Send Email from XAMPP or WAMP - Use SMTP server to send email from localhost using PHP. Example code snippet to send HTML email from localhost with PHPMailer and Gmail SMTP in PHP.","og_url":"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2016-02-25T17:12:48+00:00","article_modified_time":"2022-08-03T15:36:40+00:00","og_image":[{"width":1366,"height":768,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/how-to-send-email-from-localhost-server-in-php.png","type":"image\/png"}],"author":"CodexWorld","twitter_card":"summary_large_image","twitter_creator":"@codexworldblog","twitter_site":"@codexworldweb","twitter_misc":{"Written by":"CodexWorld","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"How to Send Email from Localhost in PHP","datePublished":"2016-02-25T17:12:48+00:00","dateModified":"2022-08-03T15:36:40+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/"},"wordCount":335,"commentCount":50,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/how-to-send-email-from-localhost-server-in-php.png","keywords":["Email","HTML Email","Localhost","PHP","PHPMailer","WAMP","XAMPP"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/","url":"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/","name":"How to Send Email from Localhost in PHP - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/how-to-send-email-from-localhost-server-in-php.png","datePublished":"2016-02-25T17:12:48+00:00","dateModified":"2022-08-03T15:36:40+00:00","description":"Send Email from XAMPP or WAMP - Use SMTP server to send email from localhost using PHP. Example code snippet to send HTML email from localhost with PHPMailer and Gmail SMTP in PHP.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/how-to-send-email-from-localhost-server-in-php.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/how-to-send-email-from-localhost-server-in-php.png","width":1366,"height":768,"caption":"how-to-send-email-from-localhost-server-in-php"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/how-to-send-email-from-localhost-in-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"How to Send Email from Localhost in PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.codexworld.com\/#website","url":"https:\/\/www.codexworld.com\/","name":"CodexWorld","description":"Web &amp; Mobile App Development Company","publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codexworld.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codexworld.com\/#organization","name":"CodexWorld","url":"https:\/\/www.codexworld.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","width":200,"height":19,"caption":"CodexWorld"},"image":{"@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldweb","https:\/\/www.linkedin.com\/company\/codexworld","https:\/\/www.youtube.com\/codexworld"]},{"@type":"Person","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0","name":"CodexWorld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","caption":"CodexWorld"},"description":"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.","sameAs":["http:\/\/www.codexworld.com","https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldblog"],"url":"https:\/\/www.codexworld.com\/author\/nitya192265\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/how-to-send-email-from-localhost-server-in-php.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-kM","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/comments?post=1288"}],"version-history":[{"count":8,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1288\/revisions"}],"predecessor-version":[{"id":5022,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1288\/revisions\/5022"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/5023"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=1288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=1288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=1288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}