Skip to main content

Linux – The PHP Mail function is disabled on shared hosting

In this tutorial we see how to overcome the disabled PHP Mail function on shared hosting with similar solutions. The PHP Mail function is often used to generate uncontrolled spam, especially on sites created with CMS such as WordPress or Joomla without the appropriate verification precautions on sending emails, however, the LAMP stacks of dedicated servers or virtual servers are not involved.

Using CodeIgniter Framework

If the application uses the CodeIgniter Framework you can remedy the email problem with this simple code. For complete functionalities, consult the documentation on

$this->email->from(‘’, ‘Momit SRL’);
$this->email->to($email); // $email = “email_id”
$this->email->subject(‘Welcome to Momit.’);
<p><b>Here write the content of the email..</b></p>

Using the PEAR library

The PEAR library has also integrated the management function for sending mail and supports SMTP authentication using an existing account defined on the domain.

include(‘Mail.php’); // PEAR Mail function

$headers = array (‘From’ => $from, ‘To’ => $to, ‘Subject’ => $subject); 
// mail header 

$smtp = Mail::factory(‘smtp’, array (‘host’ => “localhost”, ‘auth’ => true,
‘username’ => $username, ‘password’ => $password, ‘port’ => ‘587’)); 
// SMTP parameters

$mail = $smtp->send($to, $headers, $body); // sending mail

Using SwiftMailer

SwiftMailer is another method of sending emails from your site. Again it supports SMTP authentication using an existing account defined on the domain.

$mailer = Swift_Mailer::newInstance($transport);


$message = Swift_Message::newInstance();

$message->setSubject(‘E-mail subject’);
$message->setFrom(array(‘’ => ‘Sender Name’));

$message->addPart(‘<p>If <b>HTML is necessary, use addPart()</b> in the body of the e-mail </p>’, ‘text/html’);
$result = $mailer->send($message); // returns FALSE if email sending fails

Using SendGrid

SendGrid is an external service that allows you to send thousands of emails via HTTP simply by creating an account and integrating an API Key. For complete documentation, visit

$sendgrid = new SendGrid($api_user, $api_key);
$email = new SendGridEmail();
 ->setSubject("Email subject")
 ->setHtml("Email body, can contain HTML");

Do you have any issue configuring mail senders in your PHP website?

Please contact our technical support by chat or contact us by using the customer area
Momit Network Services Logo

© 2015 - 2023 MOMIT
All Rights Reserved
Viale Enrico Forlanini, 23 20134 Milano
P.IVA / C.F IT07634600964
Tel. +39 02 87187306