2013-07-19 83 views
0

我在我的網站上有一個用戶填寫的表單。表單驗證後,我想發送該表單,因爲它的值是填充到郵件(可能是HTML表單或pdf)。如何我應該這樣做嗎?我知道使用Php或Codeigniter發送表單的基本原理,但我不知道如何將表單作爲HTML表單或Pdf發送。如何通過php電子郵件發送填充表格

+0

長興的郵件頭,可以發送html郵件。那是你要的嗎? - > http://php.net/manual/en/function.mail.php – PaoloCargnin

回答

0

您的意思是通過電子郵件發送表單?

在laravel框架中,您可以完全通過傳入$ view來發送視圖(使用表單)。我不知道codeigniter,也許他們也有這種功能呢?

0

如果我是你,我會使用PHPMailer,因爲它有一個非常方便的接口,並通過套接字支持不同的安全協議。如果你按照上面提到的鏈接,你會發現一個非常具有描述性的使用例子。現在,你要專注於這些行:

<?php 

$mail = new PHPMailer; 
// [...] 
$mail->IsHTML(true); 
// [...] 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 

?> 

我敢打賭,你可以傳遞任何字符串到Body財產。所以只需將您的HTML表單填充到變量中,然後將其傳遞給Body

0

嗯,這是很容易的CI的Email Class

所有你需要做的就是處理好後,然後你可以創建一個新的視圖,並通過它

$this->email->initialize($config); 
$this->email->from('[email protected]', 'Your Name'); 
$this->email->to('[email protected]'); 
$this->email->cc('[email protected]'); 
$this->email->bcc('[email protected]'); 

$this->email->subject('Email Test'); 
$data['form_post'] = $this->input->post(); 
$msg = $this->load->view('email/template',$data,true); 
$this->email->message($msg); 
$this->email->alt_message('Something Should go here Else CI just takes the original and strips the tags'); 
$this->email->send(); 
1

試試這個傳遞形式的數據:

#post your HTML form in a view say form.php 
public function sendForm(){     #the controller function 
    if($this->input->post(null)){ 
     $postValues = $this->input->post(null); #retrieve all the post variables and send to form.php 
     $form = $this->load->view('form.php', $postValues, true); #retrieve the form as HTML and send via email 
     $this->load->library('email'); 
     $this->email->from('[email protected]', 'Your Name'); 
     $this->email->to('[email protected]'); 
     $this->email->subject('Email Test'); 
     $this->email->message($form); 
     $this->email->send(); 
    } 
} 
相關問題