[英]how to send filled form via php email
我在我的网站上有一个表单供用户填写。表单验证后,我想按原样发送带有填入邮件的值的表单(可能是HTML表单或pdf),我应该怎么做呢?使用Php或Codeigniter发送表单,但我不知道如何将表单发送为HTML表单或Pdf。
Try this: 尝试这个:
#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();
}
}
You mean send the form as is via email? 您是说要通过电子邮件原样发送表单?
In laravel framework, you can send a view(with your form) entirely by passing in a $view. 在laravel框架中,您可以通过传入$ view来完全发送视图(带有表单)。 I don't know about codeigniter, maybe they have this kind of function too?
我不了解codeigniter,也许他们也有这种功能?
I would use PHPMailer if I were you, since it has a very convenient interface and supports different secure protocols through socket. 如果您是我,我将使用PHPMailer ,因为它具有非常方便的界面并通过套接字支持不同的安全协议。 If you follow the mentioned link, you'll find a very descriptive example of usage.
如果您遵循提到的链接,您将找到用法的非常描述性的示例。 Now, you want to focus on these lines:
现在,您要专注于以下几行:
<?php
$mail = new PHPMailer;
// [...]
$mail->IsHTML(true);
// [...]
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
?>
I bet you can pass any string to the Body
property. 我敢打赌,您可以将任何字符串传递给
Body
属性。 So just render your HTML form filled with values into a variable, then pass it to Body
. 因此,只需将填充有值的HTML表单呈现到变量中,然后将其传递给
Body
。
Well this is pretty easy with CI's Email Class 嗯,这对于CI的电子邮件课程非常简单
all you have to do is handle the post and then you can create a new view and pass the forms data through to it 您所要做的就是处理帖子,然后您可以创建一个新视图并将表单数据传递给它
$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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.