简体   繁体   English

如何通过PHP电子邮件发送填写好的表格

[英]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.

相关问题 如何使用php通过电子邮件发送动态填充的HTML? - How to send dynamically filled HTML via email with php? 如何在 PHP 中发送带有已填写表格 pdf 作为附件的电子邮件? - How to send an email with a filled form pdf as attachment in PHP? 如何使用php表单通过电子邮件发送Div Tag内容? - How to send Div Tag content via email using php form? 如何通过php脚本将多个输入从表单发送到电子邮件 - How to send multiple inputs from form to email via php script 使用PHP通过电子邮件发送联系表 - Contact Form send via email using PHP 通过PHP发送选择表格到电子邮件 - Send a Select Form via PHP to Email 仅发送填充的字段框。 如果为空,则不要发送电子邮件。 PHP表格发送电子邮件 - send only field boxes filled. if empty then do not send in email. php form to email PHP获取已填写的电子邮件并向该电子邮件发送消息? - PHP get the email that was filled in and send a message to that email? 如何使用PHP将填写好的表格邮寄到电子邮件地址? - how to Mail a filled up form to an email address using PHP? PHP:只有在用户点击“发送”后,才发送包含用户填写表格的数据的电子邮件? (数据是一个数组) - PHP: Send an email with the data the user filled in a form, only after the user hit “send”? (the data is an array)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM