{"id":4123,"date":"2017-07-06T15:30:41","date_gmt":"2017-07-06T15:30:41","guid":{"rendered":"https:\/\/www.truehost.co.ke\/support\/?post_type=ht_kb&#038;p=4123"},"modified":"2024-06-07T13:04:17","modified_gmt":"2024-06-07T13:04:17","password":"","slug":"sending-on-custom-application-or-website-custom-contact-forms-via-smtp","status":"publish","type":"docs","link":"https:\/\/truehost.com\/support\/knowledge-base\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\/","title":{"rendered":"Sending mails using PHPMailer"},"content":{"rendered":"<p><strong>Use case<\/strong>: If you have coded your site using PHP, this is for you. Note that, you need to download the PHP Mailer plugin from https:\/\/github.com\/PHPMailer\/PHPMailer<\/p>\n<p><u>Sending on Custom application or website\/ Custom Contact forms<\/u><\/p>\n<p><u>Error:<\/u><\/p>\n<p>The email could not be sent.<br \/>\nPossible reason: your host may have disabled the mail() function.<\/p>\n<p><u>Recreating Error<\/u><\/p>\n<p>Error is obtained when send an email via contact form such as reset password.<\/p>\n<p><u>Causes of the Errors<\/u><\/p>\n<p>Disabled mail() or PHP Mail function on that particular Server.<\/p>\n<p><u>Why is it Disabled<\/u><\/p>\n<p>Most host providers disable mail() function from the server to curb spamming and therefore safeguard server performance and credibility of their emails and general services.<\/p>\n<p>Mail() function allow email sending without authentication so any contact form can be used by anyone (user nobody) to send any amount of mails.<\/p>\n<p>Hosting companies prefer users to use SMTP instead mail<\/p>\n<p><u>Solutions<\/u><\/p>\n<p>Configure SMTP mail Server<\/p>\n<p>For Custom website create a sending page with the following settings<\/p>\n<p>Download and Install \/ Place PHPMailer in your root directory.<\/p>\n<p>Use the following custom code to send your email.<\/p>\n<h6>&lt;?phprequire &#8216;PHPMailerAutoload.php&#8217;;<\/h6>\n<h6>$mail = new PHPMailer;\u00a0\/\/$mail-&gt;SMTPDebug = 3;\u00a0\u00a0\u00a0\u00a0 \u00a0\/\/ Enable verbose debug output<\/h6>\n<h6>$mail-&gt;isSMTP(); \u00a0 \u00a0 \/\/ Set mailer to use SMTP<\/h6>\n<h6>$mail-&gt;Host = &#8216;mail.example.com;servername.truehost.cloud&#8217;;\u00a0 \/\/ Specify main and backup SMTP servers<\/h6>\n<h6>$mail-&gt;SMTPAuth = true; \u00a0 \/\/ Enable SMTP authentication<\/h6>\n<h6>$mail-&gt;Username = &#8216;user@example.com&#8217;; \u00a0 \u00a0 \/\/ SMTP username<\/h6>\n<h6>$mail-&gt;Password = &#8216;secret&#8217;; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/ SMTP password<\/h6>\n<h6>$mail-&gt;SMTPSecure = &#8216;tls&#8217;; \u00a0 \u00a0 \u00a0 \u00a0\/\/ Enable TLS encryption, `ssl` also accepted<\/h6>\n<h6>$mail-&gt;Port = 587; \u00a0 \u00a0 \u00a0\/\/ TCP port to connect to or 25 for non secure<\/h6>\n<h6>$mail-&gt;setFrom(&#8216;from@example.com&#8217;, &#8216;Mailer&#8217;);<\/h6>\n<h6>$mail-&gt;addAddress(&#8216;joe@example.net&#8217;, &#8216;Joe User&#8217;);\u00a0\u00a0\u00a0\u00a0 \/\/ Add a recipient<\/h6>\n<h6>$mail-&gt;addAddress(&#8216;ellen@example.com&#8217;);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Name is optional<\/h6>\n<h6>$mail-&gt;addReplyTo(&#8216;info@example.com&#8217;, &#8216;Information&#8217;);<\/h6>\n<h6>$mail-&gt;addCC(&#8216;cc@example.com&#8217;);<\/h6>\n<h6>$mail-&gt;addBCC(&#8216;bcc@example.com&#8217;);<\/h6>\n<h6>$mail-&gt;addAttachment(&#8216;\/var\/tmp\/file.tar.gz&#8217;);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Add attachments<\/h6>\n<h6>$mail-&gt;addAttachment(&#8216;\/tmp\/image.jpg&#8217;, &#8216;new.jpg&#8217;);\u00a0\u00a0\u00a0 \/\/ Optional name<\/h6>\n<h6>$mail-&gt;isHTML(true); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/ Set email format to HTML<\/h6>\n<h6>$mail-&gt;Subject = &#8216;Here is the subject&#8217;;<\/h6>\n<h6>$mail-&gt;Body\u00a0\u00a0\u00a0 = &#8216;This is the HTML message body &lt;b&gt;in bold!&lt;\/b&gt;&#8217;;<\/h6>\n<h6>$mail-&gt;AltBody = &#8216;This is the body in plain text for non-HTML mail clients&#8217;;<\/h6>\n<h6>if(!$mail-&gt;send()) {\u00a0\u00a0\u00a0 echo &#8216;Message could not be sent.&#8217;;\u00a0\u00a0\u00a0 echo &#8216;Mailer Error: &#8216; .<\/h6>\n<h6>$mail-&gt;ErrorInfo;} else {\u00a0\u00a0\u00a0 echo &#8216;Message has been sent&#8217;;}<\/h6>\n<p>Read More <a href=\"https:\/\/github.com\/PHPMailer\/PHPMailer\">https:\/\/github.com\/PHPMailer\/PHPMailer<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use case: If you have coded your site using PHP, this is for you. Note that, you need to download the PHP Mailer plugin from https:\/\/github.com\/PHPMailer\/PHPMailer Sending on Custom application or website\/ Custom Contact forms Error: The email could not be sent. Possible reason: your host may have disabled the mail() function. Recreating Error Error [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_eb_attr":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"doc_category":[],"doc_tag":[],"class_list":["post-4123","docs","type-docs","status-publish","hentry"],"year_month":"2026-06","word_count":409,"total_views":"0","reactions":{"happy":"24","normal":"0","sad":"0"},"author_info":{"name":"kt","author_nicename":"truehost","author_url":"https:\/\/truehost.com\/support\/author\/truehost\/"},"doc_category_info":[],"doc_tag_info":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Sending mails using PHPMailer -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/truehost.com\/support\/knowledge-base\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sending mails using PHPMailer -\" \/>\n<meta property=\"og:description\" content=\"Use case: If you have coded your site using PHP, this is for you. Note that, you need to download the PHP Mailer plugin from https:\/\/github.com\/PHPMailer\/PHPMailer Sending on Custom application or website\/ Custom Contact forms Error: The email could not be sent. Possible reason: your host may have disabled the mail() function. Recreating Error Error [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/truehost.com\/support\/knowledge-base\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-06-07T13:04:17+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\\\/\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\\\/\",\"name\":\"Sending mails using PHPMailer -\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/#website\"},\"datePublished\":\"2017-07-06T15:30:41+00:00\",\"dateModified\":\"2024-06-07T13:04:17+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/truehost.com\\\/support\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Sending mails using PHPMailer\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/#website\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/\",\"name\":\"\",\"description\":\"Help In a Click\",\"publisher\":{\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/truehost.com\\\/support\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/#organization\",\"name\":\"Truehost Kenya\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/cropped-image_2026-04-16_174808866.png\",\"contentUrl\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/cropped-image_2026-04-16_174808866.png\",\"width\":240,\"height\":48,\"caption\":\"Truehost Kenya\"},\"image\":{\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Sending mails using PHPMailer -","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:\/\/truehost.com\/support\/knowledge-base\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\/","og_locale":"en_US","og_type":"article","og_title":"Sending mails using PHPMailer -","og_description":"Use case: If you have coded your site using PHP, this is for you. Note that, you need to download the PHP Mailer plugin from https:\/\/github.com\/PHPMailer\/PHPMailer Sending on Custom application or website\/ Custom Contact forms Error: The email could not be sent. Possible reason: your host may have disabled the mail() function. Recreating Error Error [&hellip;]","og_url":"https:\/\/truehost.com\/support\/knowledge-base\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\/","article_modified_time":"2024-06-07T13:04:17+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/truehost.com\/support\/knowledge-base\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\/","url":"https:\/\/truehost.com\/support\/knowledge-base\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\/","name":"Sending mails using PHPMailer -","isPartOf":{"@id":"https:\/\/truehost.com\/support\/#website"},"datePublished":"2017-07-06T15:30:41+00:00","dateModified":"2024-06-07T13:04:17+00:00","breadcrumb":{"@id":"https:\/\/truehost.com\/support\/knowledge-base\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/truehost.com\/support\/knowledge-base\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/truehost.com\/support\/knowledge-base\/sending-on-custom-application-or-website-custom-contact-forms-via-smtp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/truehost.com\/support\/"},{"@type":"ListItem","position":2,"name":"Sending mails using PHPMailer"}]},{"@type":"WebSite","@id":"https:\/\/truehost.com\/support\/#website","url":"https:\/\/truehost.com\/support\/","name":"","description":"Help In a Click","publisher":{"@id":"https:\/\/truehost.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/truehost.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/truehost.com\/support\/#organization","name":"Truehost Kenya","url":"https:\/\/truehost.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/truehost.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2026\/04\/cropped-image_2026-04-16_174808866.png","contentUrl":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2026\/04\/cropped-image_2026-04-16_174808866.png","width":240,"height":48,"caption":"Truehost Kenya"},"image":{"@id":"https:\/\/truehost.com\/support\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs\/4123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/comments?post=4123"}],"version-history":[{"count":2,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs\/4123\/revisions"}],"predecessor-version":[{"id":6266,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs\/4123\/revisions\/6266"}],"wp:attachment":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/media?parent=4123"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/doc_category?post=4123"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/doc_tag?post=4123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}