{"id":757,"date":"2012-03-14T19:42:29","date_gmt":"2012-03-14T19:42:29","guid":{"rendered":"http:\/\/www.websitedesignwebsitedevelopment.com\/?p=757"},"modified":"2014-03-19T09:13:54","modified_gmt":"2014-03-19T09:13:54","slug":"php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function","status":"publish","type":"post","link":"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/","title":{"rendered":"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function"},"content":{"rendered":"<h2>PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function<\/h2>\n<p>\/\/I AM USING HTTP POT VARS BECAUSE WE ARE GETTING VARIABLES FROM HTML FILE, IF WE USE PHP FILE THEN WE CAN USE $_POST &amp; $_GET<\/p>\n<p>$random_hash = md5(date(&#8216;r&#8217;, time()));<\/p>\n<p>$what_to_replace = array(&#8216;contact_&#8217;,&#8217;_&#8217;);<br \/>\n$replace_with = &#8216; &#8216;;\/\/WE WANA REPLACE UNDERSCORES WITH SPACES<\/p>\n<p>$http_vars = $_POST; \/\/WE ARE GETTING AN ARRAY<br \/>\n\/\/print_r($http_vars);<\/p>\n<p>$bad_array = array(&#8216;x&#8217;,&#8217;y&#8217;,&#8217;redirection&#8217;);<br \/>\n$for_db = array();<br \/>\n\/\/FOR THIS WE HAVE TO USE FOREACH LOOP, BECAUSE WE NEED INDEXES AS NAMES AND VALUES AS VALUES<br \/>\n$data = &#8216;&lt;table&gt;&#8217;;\/\/USING SINGLE QUOTE BECAUSE ITS JUST STRING<br \/>\nforeach($http_vars as $name=&gt;$values)<br \/>\n{<\/p>\n<p>if(substr(strtolower($name),0,8)==&#8217;contact_&#8217;)\/\/IF FIELD NAME IS NOT SUBMIT THEN APPEND THIS VARIABLE ELSE NOT, WE WANA SKIP SUBMIT<br \/>\n{<br \/>\n\/\/\u00a0\u00a0 \u00a0WE WANA FORMATE FIELD NAMES PROPERLY WITHOUT ANY UNDERSCORE AND ALSO FIRST LETTER CAPITAL, so<br \/>\n$name = str_replace($what_to_replace,&#8217; &#8216;,$name);<\/p>\n<p>$name = ucwords($name);\/\/WE WANA EVERY WORD WITH UPPER CASE STARTING<\/p>\n<p>if(is_array($values) &amp;&amp; count($values)&gt;0)<br \/>\n{<br \/>\n$values = implode(&#8216;, &#8216;,$values);<br \/>\n}<br \/>\n\/\/USING DOT BECAUSE I WANA APPEND DATA VARIABLE NOT OVERWRITE THAT<br \/>\n$data.= &#8216;&lt;tr&gt;&lt;td valign=&#8221;top&#8221;&gt;&lt;b&gt;&#8217;.$name.&#8217;:&lt;\/b&gt; &lt;\/td&gt;&lt;td&gt;&#8217;.$values.'&lt;\/td&gt;&lt;\/tr&gt;&#8217;;<br \/>\n\/\/FIRT TD MEANS LEFT COLUMN, WILL DISPLAY ALL THE CAPTIONS<br \/>\n\/\/SECOND TD MEANS RIGHT COLUMN, WILL DISPLAY VALUES<br \/>\n\/\/TR WILL BREAK THE ROW AND WE WILL GO TO NEXT ROW<br \/>\n$for_db[$name]=$values;<br \/>\n}<\/p>\n<p>}<\/p>\n<p>$data.='&lt;\/table&gt;&#8217;;<\/p>\n<p>$domain = str_replace(&#8216;www.&#8217;, &#8221;, $_SERVER[&#8216;HTTP_HOST&#8217;]);<\/p>\n<p>$subject = &#8216;Contact Enquiry from &#8216;.$domain.&#8217;\u00a0 &#8216;.date(&#8216;d M, Y&#8217;);<\/p>\n<p>$host = &#8220;mail.&#8221;.$domain;<\/p>\n<p>$username = &#8220;enquiry@&#8221;.$domain;<\/p>\n<p>$password = &#8220;*********&#8221;;<\/p>\n<p>$from = &#8220;vws enquiry &lt;$username&gt;&#8221;;<br \/>\n$to = &#8220;admin email address&#8221;;\/\/<\/p>\n<p>$headers = array (&#8216;From&#8217; =&gt; $from,<br \/>\n&#8216;To&#8217; =&gt; $to,<br \/>\n&#8216;Subject&#8217; =&gt; $subject,<br \/>\n&#8216;Content-Type&#8217; =&gt; &#8216;text\/HTML; charset=ISO-8859-1\\n&#8217;);<br \/>\n$smtp = Mail::factory(&#8216;smtp&#8217;,<br \/>\narray (&#8216;host&#8217; =&gt; $host,<br \/>\n&#8216;auth&#8217; =&gt; true,<br \/>\n&#8216;username&#8217; =&gt; $username,<br \/>\n&#8216;password&#8217; =&gt; $password));<\/p>\n<p>$mail = $smtp-&gt;send($to, $headers, $data);<\/p>\n<p>if (PEAR::isError($mail)) {<br \/>\necho(&#8220;&lt;p&gt;&#8221; . $mail-&gt;getMessage() . &#8220;&lt;\/p&gt;&#8221;);<br \/>\n} else {<br \/>\necho(&#8220;&lt;p&gt;Message successfully sent!&lt;\/p&gt;&#8221;);<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function \/\/I AM USING HTTP POT VARS BECAUSE WE ARE GETTING VARIABLES FROM HTML FILE, IF WE USE PHP FILE THEN WE CAN USE $_POST &amp; $_GET $random_hash = md5(date(&#8216;r&#8217;, time())); $what_to_replace = array(&#8216;contact_&#8217;,&#8217;_&#8217;); $replace_with = &#8216; &#8216;;\/\/WE WANA REPLACE UNDERSCORES WITH SPACES $http_vars [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9,1],"tags":[],"class_list":["post-757","post","type-post","status-publish","format-standard","hentry","category-php-email","category-website-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function<\/title>\n<meta name=\"description\" content=\"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function\" \/>\n<meta property=\"og:description\" content=\"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function\" \/>\n<meta property=\"og:url\" content=\"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/\" \/>\n<meta property=\"og:site_name\" content=\"AndroidBubble Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/pages\/Website-Design-Website-Development\/172363336135453\" \/>\n<meta property=\"article:published_time\" content=\"2012-03-14T19:42:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-03-19T09:13:54+00:00\" \/>\n<meta name=\"author\" content=\"Fahad\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Fahad\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/\"},\"author\":{\"name\":\"Fahad\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7\"},\"headline\":\"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function\",\"datePublished\":\"2012-03-14T19:42:29+00:00\",\"dateModified\":\"2014-03-19T09:13:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/\"},\"wordCount\":373,\"articleSection\":[\"PHP Email\",\"Website Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/\",\"url\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/\",\"name\":\"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function\",\"isPartOf\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/#website\"},\"datePublished\":\"2012-03-14T19:42:29+00:00\",\"dateModified\":\"2014-03-19T09:13:54+00:00\",\"author\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7\"},\"description\":\"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function\",\"breadcrumb\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/androidbubble.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Website Development\",\"item\":\"https:\/\/androidbubble.com\/blog\/category\/website-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PHP Email\",\"item\":\"https:\/\/androidbubble.com\/blog\/category\/website-development\/php-email\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#website\",\"url\":\"https:\/\/androidbubble.com\/blog\/\",\"name\":\"AndroidBubble Blog\",\"description\":\"Articles &amp; Posts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/androidbubble.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7\",\"name\":\"Fahad\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g\",\"caption\":\"Fahad\"},\"sameAs\":[\"http:\/\/www.androidbubbles.com\/\",\"https:\/\/x.com\/phpFlex\"],\"url\":\"https:\/\/androidbubble.com\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function","description":"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function","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:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/","og_locale":"en_US","og_type":"article","og_title":"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function","og_description":"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function","og_url":"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/","og_site_name":"AndroidBubble Blog","article_publisher":"https:\/\/www.facebook.com\/pages\/Website-Design-Website-Development\/172363336135453","article_published_time":"2012-03-14T19:42:29+00:00","article_modified_time":"2014-03-19T09:13:54+00:00","author":"Fahad","twitter_misc":{"Written by":"Fahad","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/#article","isPartOf":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/"},"author":{"name":"Fahad","@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7"},"headline":"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function","datePublished":"2012-03-14T19:42:29+00:00","dateModified":"2014-03-19T09:13:54+00:00","mainEntityOfPage":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/"},"wordCount":373,"articleSection":["PHP Email","Website Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/","url":"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/","name":"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function","isPartOf":{"@id":"https:\/\/androidbubble.com\/blog\/#website"},"datePublished":"2012-03-14T19:42:29+00:00","dateModified":"2014-03-19T09:13:54+00:00","author":{"@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7"},"description":"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function","breadcrumb":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-smtp-email-mail-php-rackspace-cloud-hosting-pear-mail-authenticated-email-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/androidbubble.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Website Development","item":"https:\/\/androidbubble.com\/blog\/category\/website-development\/"},{"@type":"ListItem","position":3,"name":"PHP Email","item":"https:\/\/androidbubble.com\/blog\/category\/website-development\/php-email\/"},{"@type":"ListItem","position":4,"name":"PHP SMTP Email, Mail.php, Rackspace Cloud Hosting, Pear Mail, Authenticated Email Function"}]},{"@type":"WebSite","@id":"https:\/\/androidbubble.com\/blog\/#website","url":"https:\/\/androidbubble.com\/blog\/","name":"AndroidBubble Blog","description":"Articles &amp; Posts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/androidbubble.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7","name":"Fahad","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g","caption":"Fahad"},"sameAs":["http:\/\/www.androidbubbles.com\/","https:\/\/x.com\/phpFlex"],"url":"https:\/\/androidbubble.com\/blog\/author\/admin\/"}]}},"views":925,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/comments?post=757"}],"version-history":[{"count":4,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/757\/revisions"}],"predecessor-version":[{"id":1632,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/757\/revisions\/1632"}],"wp:attachment":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/media?parent=757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/categories?post=757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/tags?post=757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}