{"id":1251,"date":"2021-12-08T09:40:20","date_gmt":"2021-12-08T09:40:20","guid":{"rendered":"https:\/\/ownwebservers.com\/kb\/?p=1251"},"modified":"2021-12-08T12:59:09","modified_gmt":"2021-12-08T12:59:09","slug":"php-mail-function-disabled-on-shared-web-hosting-2","status":"publish","type":"post","link":"https:\/\/ownwebservers.com\/kb\/php-mail-function-disabled-on-shared-web-hosting-2\/","title":{"rendered":"PHP Mail Function Disabled on Shared Web Hosting"},"content":{"rendered":"<p>We had previously decided to disable the mail function because the the mail() function was typically employed by malicious users on our network to send spam and alternative uninvited e-mails. we tend to suggest our customers to use an e-mail library so as to send e-mails, there are many in which to choose from.<\/p>\n<h1>CodeIgniter Framework.<\/h1>\n<p>If you make use of the CodeIgniter framework, you can use the built-in Email class in order to send e-mails. Here is sample code using the CodeIgniter\u2019s Email class:<\/p>\n<blockquote><p>$this-&gt;load-&gt;library(\u2019email\u2019);<br \/>\n$this-&gt;email-&gt;from(\u2018noreply@eukhost.com\u2019, \u2018ownwebservers Limited (No Reply)\u2019);<br \/>\n$this-&gt;email-&gt;to($email); \/\/ $email = \u201cemail_id\u201d<br \/>\n$this-&gt;email-&gt;subject(\u2018Welcome to ownwebservers Limited.\u2019);<br \/>\n$this-&gt;email-&gt;message(\u2018&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;p&gt;&lt;b&gt;Message here&lt;\/b&gt;&lt;\/p&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;\u2019);<br \/>\n$this-&gt;email-&gt;send();<\/p><\/blockquote>\n<p>You can also autoload the Email class within the config\/autoload.php file which means you do not need to use the first line of code to instantiate the Email class before making use of it.<br \/>\nFor more information on the Email class in CodeIgniter, see the documentation.<\/p>\n<h1>PEAR Library.<\/h1>\n<p>The PEAR library also has a built-in Mail class for sending e-mails, including e-mails over SMTP authentication with an already-existing e-mail account. Here\u2019s an example:<\/p>\n<blockquote><p>include(\u2018Mail.php\u2019); \/\/ includes the PEAR Mail class<br \/>\n$headers = array (\u2018From\u2019 =&gt; $from, \u2018To\u2019 =&gt; $to, \u2018Subject\u2019 =&gt; $subject); \/\/ the email headers<br \/>\n$smtp = Mail::factory(\u2018smtp\u2019, array (\u2018host\u2019 =&gt; \u201clocalhost\u201d, \u2018auth\u2019 =&gt; true, \u2018username\u2019 =&gt; $username, \u2018password\u2019 =&gt; $password, \u2018port\u2019 =&gt; \u2018587\u2019)); \/\/ SMTP protocol with the username and password of an existing email account in your hosting account<br \/>\n$mail = $smtp-&gt;send($to, $headers, $body); \/\/ sending the email<\/p><\/blockquote>\n<p>For more information, see the page on the Mail class on the PEAR website.<br \/>\nNote: The code above does not catch any errors so we\u2019d recommend you check the documentation for more elaborative examples.<\/p>\n<p>To find the SMTP port, go to \u201cConfigure Email Client\u201d under the \u201cMore\u201d menu within \u201cEmail Accounts\u201d of cPanel. It may be port 587, but check to be sure.<\/p>\n<article id=\"post-3042\" class=\"post-3042 post type-post status-publish format-standard hentry category-linux-hosting tag-disabled tag-library tag-mail tag-mail-function tag-php tag-reseller-hosting-2 tag-shared-hosting tag-smtp ast-article-single\">\n<div class=\"ast-post-format- ast-no-thumb single-layout-1\">\n<div class=\"entry-content clear\">\n<h1>SwiftMailer Library.<\/h1>\n<p>The SwiftMailer library is another popular choice for sending e-mails. Here\u2019s an example:<br \/>\n$transport = Swift_SmtpTransport::newInstance(\u2018mail.example.com\u2019, 587); \/\/ your mail server address and port. If you don\u2019t know what yours is, go to cPanel -&gt; E-mail Settings and for the specific e-mail account, More -&gt; Configure E-mail Client \u2013 it will be displayed there.<\/p>\n<blockquote><p>$mailer = Swift_Mailer::newInstance($transport); \/\/ creates new instance of an SMTP transport specifically<\/p>\n<p>$transport-&gt;setUsername(\u2018email@example.com\u2019);<br \/>\n$transport-&gt;setPassword(\u2018your_password_here\u2019);<\/p>\n<p>$message = Swift_Message::newInstance();<\/p>\n<p>$message-&gt;setSubject(\u2018Set the subject of the e-mail\u2019);<br \/>\n$message-&gt;setFrom(array(\u2018email@example.com\u2019 =&gt; \u2018Your Name\/Company Name\u2019));<br \/>\n$message-&gt;setTo(array($email));<\/p>\n<p>$message-&gt;addPart(\u2018&lt;p&gt;If you want &lt;b&gt;HTML in your e-mail use addPart()&lt;\/b&gt;&lt;\/p&gt;\u2019, \u2018text\/html\u2019);<\/p>\n<p>$result = $mailer-&gt;send($message); \/\/ returns FALSE boolean on failure<\/p>\n<p>if(!$result)<br \/>\n{<br \/>\necho \u2018failure\u2019;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\necho \u2018success\u2019;<br \/>\n}<\/p><\/blockquote>\n<p>Feel free to contact our staff member for any help.<\/p>\n<\/div>\n<\/div>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>We had previously decided to disable the mail function because the the mail() function was typically employed by malicious users on our network to send spam and alternative uninvited e-mails. we tend to suggest our customers to use an e-mail library so as to send e-mails, there are many in which to choose from. CodeIgniter [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-1251","post","type-post","status-publish","format-standard","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v15.2.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP Mail Function Disabled on Shared Web Hosting - OWS KB<\/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:\/\/ownwebservers.com\/kb\/php-mail-function-disabled-on-shared-web-hosting-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Mail Function Disabled on Shared Web Hosting - OWS KB\" \/>\n<meta property=\"og:description\" content=\"We had previously decided to disable the mail function because the the mail() function was typically employed by malicious users on our network to send spam and alternative uninvited e-mails. we tend to suggest our customers to use an e-mail library so as to send e-mails, there are many in which to choose from. CodeIgniter [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ownwebservers.com\/kb\/php-mail-function-disabled-on-shared-web-hosting-2\/\" \/>\n<meta property=\"og:site_name\" content=\"OWS KB\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-08T09:40:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-08T12:59:09+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\">\n\t<meta name=\"twitter:data1\" content=\"admin\">\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\":\"WebSite\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/#website\",\"url\":\"https:\/\/ownwebservers.com\/kb\/\",\"name\":\"OWS KB\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/ownwebservers.com\/kb\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/php-mail-function-disabled-on-shared-web-hosting-2\/#webpage\",\"url\":\"https:\/\/ownwebservers.com\/kb\/php-mail-function-disabled-on-shared-web-hosting-2\/\",\"name\":\"PHP Mail Function Disabled on Shared Web Hosting - OWS KB\",\"isPartOf\":{\"@id\":\"https:\/\/ownwebservers.com\/kb\/#website\"},\"datePublished\":\"2021-12-08T09:40:20+00:00\",\"dateModified\":\"2021-12-08T12:59:09+00:00\",\"author\":{\"@id\":\"https:\/\/ownwebservers.com\/kb\/#\/schema\/person\/4a40fe3fe17a08ddd1d7c113668e75f2\"},\"breadcrumb\":{\"@id\":\"https:\/\/ownwebservers.com\/kb\/php-mail-function-disabled-on-shared-web-hosting-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ownwebservers.com\/kb\/php-mail-function-disabled-on-shared-web-hosting-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/php-mail-function-disabled-on-shared-web-hosting-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/\",\"url\":\"https:\/\/ownwebservers.com\/kb\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/php-mail-function-disabled-on-shared-web-hosting-2\/\",\"url\":\"https:\/\/ownwebservers.com\/kb\/php-mail-function-disabled-on-shared-web-hosting-2\/\",\"name\":\"PHP Mail Function Disabled on Shared Web Hosting\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/#\/schema\/person\/4a40fe3fe17a08ddd1d7c113668e75f2\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ba5db5841d48bd7517bb2583e13983e6d2fa56a4099a0b3c61ad2daefc321303?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/ownwebservers.com\/kb\"]}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","_links":{"self":[{"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/posts\/1251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/comments?post=1251"}],"version-history":[{"count":1,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/posts\/1251\/revisions"}],"predecessor-version":[{"id":1252,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/posts\/1251\/revisions\/1252"}],"wp:attachment":[{"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/media?parent=1251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/categories?post=1251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/tags?post=1251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}