2
votes

I am using my domain details for sending the emails with CodeIgniter SMTP, but emails are not going. This is my settings:

 $full_name =  'xxx';
 $from = $email = '[email protected]';
 $configs = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'mail.manazelspecialists.ae',
      'smtp_port' => 587,
      'smtp_user' => '[email protected]',
      'smtp_pass' => 'xxxx',
      'mailtype' => 'html',
      'charset' => 'iso-8859-1',
      'wordwrap' => TRUE
    );

$this->load->library('email', $configs);
$this->email->initialize($configs);

$msg = '<html><body>';
$msg.= 'msg here';
$msg.= '</body></html>';

$this->email->set_newline("\r\n");
$this->email->subject('Career Form Filled');
$this->email->from($from,$full_name);
$this->email->reply_to(REPLY_TO);
$this->email->to('[email protected]');
$this->email->message($msg);
$this->email->send();

and I am receiving this error: Failed to send AUTH LOGIN command. Error: Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

4
Are you trying this code with your localhost or with live server? - Himanshu Upadhyay
I am trying this on live server, with smtp.googlemail.com its working - dev
@dev, With googlemail.com you would be using port 'smtp_port' => 465? - Himanshu Upadhyay
Yes @HimanshuUpadhyay - dev

4 Answers

2
votes

change one line in the config array and try

 $configs = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://mail.manazelspecialists.ae',//change here
      'smtp_port' => 587,
      'smtp_user' => '[email protected]',
      'smtp_pass' => 'xxxx',
      'mailtype' => 'html',
      'charset' => 'iso-8859-1',
      'wordwrap' => TRUE
    );
1
votes

I think nothing is wrong with the code. You need to make sure to set up the right configs of your mail server.

1
votes

Try to change smtp_port to 25

$config = Array();

 $config['protocol']        = 'smtp';
 $config['smtp_host']       = 'mocha4004.mochahost.com';
 $config['smtp_port']       = '25';
 $config['smtp_user']       = '[email protected]';
 $config['smtp_pass']       = 'ankit123';
 $config['mailtype']        = 'html';
 $config['charset']         = 'iso-8859-1';
 $config['wordwrap']        = TRUE;
1
votes

you can try my example

public function __construct()
{
    parent::__construct();
    $this->load->library('email');
    $this->load->model('email_model');
}


public function emails()
{

    $data['emails']=$this->email_model->get_records_of_chats_with_clients();
    $this->load->view('templates/head', $data);
    $this->load->view('templates/header', $data);
    $this->load->view('email/view_emails', $data);
    $this->load->view('templates/footer');


}
public function create()
{
    $data['privileges'] = $this->email_model->get_privileges();

    $this->form_validation->set_rules('privilege', 'privilege', 'required');
    $this->form_validation->set_rules('from_name', 'from_name', 'required');
    $this->form_validation->set_rules('from_email', 'from_email', 'required');
    $this->form_validation->set_rules('to_email', 'to_email', 'required');
    $this->form_validation->set_rules('title', 'title', 'required');

    if($this->form_validation->run() === FALSE){
        $this->load->view('templates/head', $data);
        $this->load->view('templates/header', $data);
        $this->load->view('email/create_email', $data);
        $this->load->view('templates/footer');
    } else {
    $this->email_model->record_chats_with_clients();
    redirect('email/emails');
    }

}
public function kurti(){
    $data['privileges'] = $this->email_model->get_privileges();
    $email_to=$this->input->post('to_email');
    $name_input=$this->input->post('name');
    $name_session=$this->session->userdata('name');
    $title=$this->input->post('title');
    $message=$this->input->post('message');
    if(!isset($name_input)){
        $name=$name_session;
    } else{
        $name=$name_input;
    }

    $this->email->from('[email protected]', $name);
    $this->email->to($email_to);
    $this->email->subject($title);
    $this->email->message($message);
    $config = array(
        'protocol' => 'smtp',
        'smtp_host' => 'example.serveriai.lt',
        'smtp_port' => 587,
        'smtp_user' => '[email protected]',
        'smtp_pass' => 'example',
        'mailtype'  => 'html',
        'charset'   => 'iso-8859-1'
    );
    $this->email->set_mailtype("html");
    $this->load->library('email', $config);

    $this->form_validation->set_rules('to_email', 'Gavėjo adresas', 'required');
    $this->form_validation->set_rules('title', 'Gavėjo žinutės tema', 'required');
    $this->form_validation->set_rules('message', 'Žinutė', 'required');

    if($this->form_validation->run() === FALSE){
        $this->load->view('templates/head');
        $this->load->view('templates/header');
        $this->load->view('email/index', $data);
        $this->load->view('templates/footer');
    } elseif ($this->email->send()) {
        $this->email_model->record_chats_with_clients($name);
        $message = "success";
        echo '
        <script type="text/javascript">alert(\''.$message.'\');
        window.location = \'/email/emails\';</script>';
    }
    else
    {
        if ($this->session->userdata('admin'=='1')){
            show_error($this->email->print_debugger());

        } else{
            $message = "error!";
            echo "<script type='text/javascript'>alert('$message');</script>";
        }

    }
}