2016-07-19 27 views
0

我試圖使用codeigniter發送電子郵件功能,但它不起作用,沒有發送,有任何幫助?如何發送郵件使用Codigniter?

這是我的控制器:

public function send_mail() { 

    $this->load->library('session'); 
    $this->load->helper('form'); 
    $this->load->view('admin/main/email_form.php'); 

    $config = Array(
    'protocol' => 'smtp', 
    'smtp_host' => 'ssl://smtp.googlemail.com', 
    'smtp_port' => 465, 
    'smtp_user' => '[email protected]', 
    'smtp_pass' => 'xxxxxx', 
    'mailtype' => 'html', 
    'charset' => 'iso-8859-1', 
    'wordwrap' => TRUE); 

    $from_email = "[email protected]"; 
    $to_email = $this->input->post('email'); 
    $subject = $this->input->post('subject'); 
    $message = $this->input->post('message'); 

    $this->load->library('email',$config); 
    $this->email->set_newline("\r\n"); 

    $this->email->from($from_email); 
    $this->email->to($to_email); 
    $this->email->subject($subject); 
    $this->email->message($message); 

    $this->email->send();  
    }  
+0

你有沒有做過任何疑難解答?看着日誌?試過任何其他設置? – Sparky

+0

如果您使用本地主機,則可能需要配置您的php.ini文件和sendmail.ini https://www.youtube.com/watch?v=TO7MfDcM-Ho – user4419336

回答

1

試試這個,檢查服務器的日誌:

$config = array(
    'protocol' => 'smtp', 
    'smtp_host' => 'smtp.gmail.com', 
    'smtp_port' => 465, // or 587 
    'smtp_user' => '[email protected]', 
    'smtp_pass' => 'xxx', 
    'charset' => 'utf-8', 
    'mailtype' => 'html' 
); 

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

$this->email->from($from_email); 
$this->email->to($to_email); 
$this->email->subject($subject); 
$this->email->message($message); 

if (!$this->email->send()) { 
    echo $this->email->print_debugger(); 
} 

更多的例子: Sending email with gmail smtp with codeigniter email library

0

你可以試試下面的代碼

 $this->load->library('email');   
     $config['protocol'] = "smtp"; 
     $config['smtp_host'] = 'mail.domain.com'; //smtp host name 
     $config['smtp_port'] = '587'; //smtp port 
     $config['smtp_user'] = '[email protected]'; //smtp username 
     $config['smtp_pass'] = '12345'; //smtp password 
     $config['mailtype'] = 'html'; 
     $config['charset'] = 'utf-8'; 
     $config['newline'] = "\r\n"; 
     $config['wordwrap'] = TRUE; 
     $this->email->initialize($config);   
     $this->email->from('[email protected]', 'website.com'); 
     $this->email->to('[email protected]');    
     $msg="This is test message"; 
     $this->email->subject('Test Subject'); 
     $this->email->message($msg); 
     $this->email->send();