Home Articles

CodeIgniter不使用SMTP发送电子邮件

Asked
Viewed 1682 times
2

我使用我的域名详细信息来发送带有CodeIgniter SMTP的电子邮件,但电子邮件不会发送 . 这是我的设置:

$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();

我收到此错误:无法发送AUTH LOGIN命令 . 错误:无法使用PHP SMTP发送电子邮件 . 您的服务器可能未配置为使用此方法发送邮件 .

4 Answers

  • 2

    你可以试试我的榜样

    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>";
            }
    
        }
    }
    
  • 1

    更改配置数组中的一行并尝试

    $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
        );
    
  • 1

    尝试将 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;
    
  • 0

    我认为代码没有问题 . 您需要确保设置邮件服务器的正确配置 .

Related