简体   繁体   English

CodeIgniter不使用SMTP发送电子邮件

[英]CodeIgniter not sending emails with SMTP

I am using my domain details for sending the emails with CodeIgniter SMTP, but emails are not going. 我正在使用我的域详细信息通过CodeIgniter SMTP发送电子邮件,但电子邮件没有发送。 This is my settings: 这是我的设置:

 $full_name =  'xxx';
 $from = $email = 'info@manazelspecilists.com';
 $configs = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'mail.manazelspecialists.ae',
      'smtp_port' => 587,
      'smtp_user' => 'support@manazelspecialists.ae',
      '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('xxxx@gmail.com');
$this->email->message($msg);
$this->email->send();

and I am receiving this error: Failed to send AUTH LOGIN command. 并且我收到此错误:无法发送AUTH LOGIN命令。 Error: Unable to send email using PHP SMTP. 错误:无法使用PHP SMTP发送电子邮件。 Your server might not be configured to send mail using this method. 您的服务器可能未配置为使用此方法发送邮件。

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' => 'support@manazelspecialists.ae',
      'smtp_pass' => 'xxxx',
      'mailtype' => 'html',
      'charset' => 'iso-8859-1',
      'wordwrap' => TRUE
    );

I think nothing is wrong with the code. 我认为代码没有错。 You need to make sure to set up the right configs of your mail server. 您需要确保设置正确的邮件服务器配置。

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('mantas@fastfood.lt', $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' => 'mantas@fastfood.lt',
        '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>";
        }

    }
}

Try to change smtp_port to 25 尝试将smtp_port更改为25

$config = Array();

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM