How to use PHPMailer in codeigniter?

I get the following error when I try to send an email using PHPMailer



2016-05-31 10:44:55 CLIENT → SERVER: EHLO localhost 2016-05-31 10:44:56 CLIENT → SERVER: MAIL FROM: 2016-05-31 10:44:56 SMTP ERROR: MAIL FROM command failed : 530-5.5.1 Authentication required. Learn more at 530 5.5.1 https://support.google.com/mail/answer/14257 v27sm39349082pfi.49 - gsmtp 2016-05-31 10:44:56 Next The address could not be completed: my.news.app@gmail .com : MAIL FROM command failed, authentication required. Find out more at https://support.google.com/mail/answer/14257 v27sm39349082pfi.49 - gsmtp, 530,5.5.1 SMTP server error: MAIL FROM command failed Details: Authentication required. Learn more at https://support.google.com/mail/answer/14257v27sm39349082pfi.49 - gsmtp SMTP code: 530 Additional SMTP information: 5.5.1 Address failed : my.news.app@gmail.com : MAIL FROM command failed, authentication required. Find out more at https://support.google.com/mail/answer/14257 v27sm39349082pfi.49 - gsmtp, 530,5.5.1 SMTP server error: MAIL FROM command failed Details: Authentication required. Find out more at https://support.google.com/mail/answer/14257 v27sm39349082pfi.49 - gsmtp SMTP code: 530 Additional information SMTP: 5.5.1 2016-05-31 10:44:56 CLIENT → SERVER: EXIT

+4
source share
2 answers

, , sendmail ​​ , CI3. , , , - . - - , . , email. - :

//run this from your controller
$this->load->library('email');
$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com');
$this->email->cc('another@another-example.com');
$this->email->bcc('them@their-example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();

, CI3 . sendmail . , :

$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

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

, PHPMailer, , elddenmedio. PHPMailer library third_party require .

Edit:

, - Google, smtp, CI3. PHPMailer:

public function send_email($to, $subject, $message) {
    $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'mail.gmx.com',
        'smtp_port' => 587, //465,
        'smtp_user' => 'myself@gmx.com',
        'smtp_pass' => 'PASSWORD',
        'smtp_crypto' => 'tls',
        'smtp_timeout' => '20',
        'mailtype'  => 'html', 
        'charset'   => 'iso-8859-1'
    );
    $config['newline'] = "\r\n";
    $config['crlf'] = "\r\n";
    $this->CI->load->library('email', $config);
    $this->CI->email->from('myself@gmx.com', 'Admin');
    $this->CI->email->to($to);
    $this->CI->email->subject($subject);
    $this->CI->email->message($message);

    //$this->email->send();
    if ( ! $this->CI->email->send()) {
        return false;
    }
    return true;
}

myself@gmx.com PASSWORD .

+6

phpmailer, /, o ( , CI_Controller ) controller.php

<?php
include 'PhpMailer.php';

class Test extends CI_Controller{
    public function __construct(){
        parent::__construct();
    }

    public function do_somthing(){
        $this->load->model('model_do');

        $data['value'] = $this->model_do->get_values();

        $view = $this->load->view('view', $data, TRUE);

        SendMail("Header", 'from@mail.com', 'Header 2', 'to@mail.com', 'Subject', $view);
    }
}
+2

All Articles