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 www.codeigniter.com/docs
$this->load->library(’email’);
$this->email->from(‘noreply@momit.eu’, ‘Momit SRL’);
$this->email->to($email); // $email = “email_id”
$this->email->subject(‘Welcome to Momit.’);
$this->email->message(‘<html>
<head>
</head>
<body>
<p><b>Here write the content of the email..</b></p>
</body>
</html>’);
$this->email->send();
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.
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);
$transport->setUsername(‘no_reply@momit.eu’);
$transport->setPassword(‘password_account’);
$message = Swift_Message::newInstance();
$message->setSubject(‘E-mail subject’);
$message->setFrom(array(‘noreply@momit.eu’ => ‘Sender Name’));
$message->setTo(array($email));
$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 www.sendgrid.com
$sendgrid = new SendGrid($api_user, $api_key);
$email = new SendGridEmail();
$email->addTo("no_reply@momit.eu")
->setFrom("no_reply@momit.eu")
->setSubject("Email subject")
->setHtml("Email body, can contain HTML");
$sendgrid->send($email);
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