【发布时间】:2017-03-08 21:16:24
【问题描述】:
您好,一旦我在请求表单中提交详细信息后,我的网站上有一个请求表单,无法向管理员发送有关请求的电子邮件。它正在重定向欢迎/请求功能,也没有收到任何错误
控制器:
class Welcome extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation', 'email'));
}
public function index()
{
$this->load->model('index_model');
$data['records2'] = $this->index_model->get_all_banners();
$data['mainpage'] = "index";
$this->load->view('templates/template',$data);
}
function request()
{
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<br /><span class="error"> ','</span>');
$this->form_validation->set_rules('name','First Name' , 'required');
$this->form_validation->set_rules('email','Email');
$this->form_validation->set_rules('phone','Mobile Number');
$this->form_validation->set_rules('description','Description');
if($this->form_validation->run()== FALSE)
{
$data['mainpage']='index';
$this->load->view('templates/template',$data);
}
else
{
//get the form data
$name = $this->input->post('name');
$from_email = $this->input->post('email');
$subject = $this->input->post('phone');
$message = $this->input->post('description');
//set to_email id to which you want to receive mails
$to_email = 'xxxxx@gmail.com';
$config=Array(
'protocol'=> 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com', //smtp host name
'smtp_port' => '465', //smtp port number
'smtp_user' => 'xxx@gmail.com',
'smtp_pass' => '*******', //$from_email password
'mailtype' =>'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
//send mail
$this->load->library('email',$config);
$this->email->from($name);
$this->email->to('$to_email');
$this->email->subject($subj);
$this->email->message($messagess1);
$this->email->set_newline("\r\n");
if ($this->email->send())
{
// mail sent
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
redirect('welcome');
}
else
{
//error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
redirect('welcome');
}
}
}
}
【问题讨论】:
-
你必须找出确切的错误,你可以通过下面的代码得到它 if ($this->email->send()) { Do your Stuff } else { show_error($CI->电子邮件->print_debugger());死;请让我知道您遇到了什么错误。
-
@vatsalshah 没有收到任何错误
-
@vatsalshah 也解决了我的问题更新答案
标签: php codeigniter email