你好,大家好我有一些問題,這意味着我不從形式reciev郵件...CodeIgnitor發送電子郵件
的代碼如下所示:
public function send_email(){
$this->load->library("form_validation");
$this->form_validation->set_rules("fullName", "Full Name", "required|alpha|xss_clean");
$this->form_validation->set_rules("email", "Email Address", "required|valid_email|xss_clean");
$this->form_validation->set_rules("message", "Message", "required|xss_clean");
if($this->form_validation->run() == FALSE){
$data["message"] = "";
$this->load->view("site_header");
$this->load->view("site_nav");
$this->load->view("content_comment", $data);
$this->load->view("site_footer");
}else{
$data["message"] = "The email was successfully been sent!";
$this->load->library("email");
$this->email->from(set_value("email"), set_value("fullName"));
$this->email->to("[email protected]");
$this->email->subject("Message from our form");
$this->email->message(set_value("message"));
$this->email->send();
echo $this->email->print_debugger();
$this->load->view("site_header");
$this->load->view("site_nav");
$this->load->view("content_comment", $data);
$this->load->view("site_footer");
}
}
,我得到一個錯誤,看起來像這樣:
無法使用PHP郵件()發送電子郵件。您的服務器可能未配置爲使用此方法發送郵件。**
這是來自我的php.ini文件嗎?
我已經把我的文件中讀取這個零件http://php.net/manual/en/ref.mail.php
我找到了解決辦法:創建配置文件:email.php看起來像這樣
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| EMAIL CONFING
| -------------------------------------------------------------------
| Configuration of outgoing mail server.
| */
$config['wordwrap'] = FALSE;
$config['mailtype'] = 'html';
$config['crlf'] = '\r\n';
$config['charset']='utf-8';
$config['newline']="\r\n";
$config['priority']=1;
$config['protocol']='smtp';
$config['smtp_host']='ssl://smtp.googlemail.com';
$config['smtp_port']='465';
$config['smtp_timeout']='30';
$config['smtp_user']='[email protected]';
$config['smtp_pass']='qwaszx12';
$config['newline']="\r\n";
/* End of file email.php */
/* Location: ./system/application/config/email.php */
然後在你的主加載此控制器如:$this->email->initialize($this->config->config);
就是這樣!
看看[這裏] [1],也許你可以找到答案。 [1]:http://stackoverflow.com/questions/3859958/codeigniter-unable-to-send-email-using-php-mail – Briganti