您好我使用"电子邮件" CodeIgniter的库。我正在创建一个联系表单,我想获取用户输入的信息并将其用于电子邮件,但我没有成功。是的我已经在网站上搜索并尝试了所提供的各种实现,但我没有成功将它们合并到我的代码中。我应该提一下,我是XodeIgniter和Web开发的新手,所以也许这对我来说更容易理解。这是我的控制器和视图。
控制器:
public function index()
{
$data['title'] = 'Contact Us';
$this->load->view('templates/header', $data);
$this->load->view('templates/navbar', $data);
$this->load->view('contact_us', $data);
$this->load->view('templates/footer', $data);
}
public function email()
{
$this->load->library('email');
$this->email->from($this->input->post('email'),$this->input->post('name'));
$this->email->to('orlandoe91@gmail.com');
//$this->email->cc('another@example.com');
//$this->email->bcc('them@example.com');
$this->email->subject($this->input->post('subject'));
$this->email->message($this->input->post('comments'));
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->send();
if ( ! $this->email->send())
{
$this->email->print_debugger();
}
else
{
$data['title'] = 'Contact confirmation';
$this->load->view('templates/header', $data);
$this->load->view('contact_form_success', $data);
$this->load->view('templates/footer', $data);
}
}
查看:
<?php
echo form_open('index.php/contact_us/submit', 'id=contact_us');
echo form_fieldset('Contact Us');
echo form_label('Name', 'name');
echo form_input('name', '');
echo br(1);
echo form_label('Email', 'email');
echo form_input('email', '');
echo br(1);
echo form_label('Subject', 'subject');
echo form_input('subject', '');
echo br(1);
echo form_label('Comments', 'comments');
echo form_textarea('comments','','id=comments');
echo br(1);
echo form_fieldset_close();
echo form_submit('submit_comment', 'Submit Comment');
echo form_close();
?>
任何帮助都将受到赞赏,或者可能在前面已经说明了对其他实现的更清楚的解释。感谢。
答案 0 :(得分:0)
在构造函数中加载库:
$这 - &GT;负载&GT;库( '电子邮件');
按照以下代码通过EMAIL CLASS发送电子邮件
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from($_POST['user_email_id'], $_POST['user_name']);
$this->email->to('enter_your_email_address');
$this->email->subject($_POST['your_custom_subject_subject']);
$this->email->message("Enter_your_custom_message_here");
if($this->email->send()){
//email send successfully do something
}else{
//email not sent do something else
}
有关codeigniter中电子邮件类的更多详细信息,请访问以下链接:
http://ellislab.com/codeigniter/user-guide/libraries/email.html