0

I have been trying to send an email from my website using PHP. However I am unable to and I keep getting this error Unable to send email using PHP mail(). Your server might not be configured to send mail using this method. The php email cofiguration has been working fine for the past one year and only recently did I start receiving this error.

I have included smtp settings in my configuration which I did not have before but I still get the same error. I have gone through the solutions provided in StackOverFlow concerning the error but none seems to work for me. I have tried to use the different smtp ports(25,465,587) but none seem to work. I have tried different smtp_crypto(ssl,tls,null) but none has worked for me. I have included the line set_newline("\r\n") in my code, I have also removed it put the error still persists. I have even contacted my web hosting service provider but have informed me the problem is not on their side.

My code for sending an email is as shown below

class EmailController extends CI_Controller {

  public function __construct() {
    parent:: __construct();

    $this->load->helper('url');
    $this->load->library('email');
  }

function send() {
    $config = Array(
    'protocol'  => 'mail',
    'smtp_host' => 'mail.(domain_name)',
    'smtp_port' =>  '465',
    'smtp_user' => '********',
    'smtp_pass' => '*********',
    'mailtype'  => 'html',
    'charset'   => 'utf-8'
   ); 

$this->email->initialize($config);

$this->email->set_newline("\r\n");

$email_body ="<div>hello world</div>";

$this->email->from('info@myemail.com');
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);

    if ($this->email->send()) {
        echo 'Your Email has successfully been sent.';
    } else {
        show_error($this->email->print_debugger());
    }
  }
}

I expect the output to be the message "Your Email has successfully been sent" and an email to be sent but I keep get the following error message;

Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

Date: Date and time stamp
From: <info@myemail.com>
Return-Path: <info@myemail.com>
Reply-To: <info@myemail.com>
User-Agent: CodeIgniter
X-Sender: info@myemail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5d234afb2e34a@myemail.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_5d234afb2e38e"
=?UTF-8?Q?Orders=20not=20being=20sent?=
This is a multi-part message in MIME format.
Your email application may not support this format.

Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

My Order

Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

My Order

How do I fix this??

lorrainemutheu
  • 115
  • 1
  • 17

0 Answers0