[英]Send Email Using input from form with CodeIgniter
您好,我在使用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();
?>
任何幫助將不勝感激,或者在更早的時候對其他實現的更清晰的解釋。 謝謝。
將庫加載到構造函數中:
$ this-> load-> library('email');
請按照以下代碼通過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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.