0

我的网站中有一个用户填写的表单。表单验证后,我想发送该表单,因为它的值填充到邮件中(可能是 HTML 表单或 pdf)。我应该怎么做?我知道基本的在使用 Php 或 Codeigniter 发送表单时,但我不知道如何将表单作为 HTML 表单或 Pdf 发送。

4

4 回答 4

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('your@example.com', 'Your Name');
        $this->email->to('someone@example.com'); 
        $this->email->subject('Email Test');
        $this->email->message($form);   
        $this->email->send();
    }
}
于 2013-07-19T07:40:29.553 回答
0

您的意思是通过电子邮件按原样发送表格?

在 laravel 框架中,您可以完全通过传入 $view 来发送视图(使用您的表单)。我不知道codeigniter,也许他们也有这种功能?

于 2013-07-19T07:23:41.283 回答
0

如果我是你,我会使用PHPMailer,因为它有一个非常方便的接口,并且通过套接字支持不同的安全协议。如果您按照提到的链接,您会发现一个非常具有描述性的用法示例。现在,您要关注以下几行:

<?php

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

?>

我敢打赌,您可以将任何字符串传递给该Body属性。因此,只需将填充了值的 HTML 表单呈现到变量中,然后将其传递给Body.

于 2013-07-19T07:29:38.023 回答
0

好吧,使用 CI 的电子邮件类很容易

您所要做的就是处理帖子,然后您可以创建一个新视图并将表单数据传递给它

$this->email->initialize($config);
$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com');
$this->email->cc('another@another-example.com');
$this->email->bcc('them@their-example.com');

$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();
于 2013-07-19T07:39:57.170 回答