如何通过php电子邮件发送填妥的表格
我在我的网站上有一个用户填写的表单。在表单验证后,我想将该表单原样发送到邮件(可能是HTML表单或pdf)。我该怎么做?我知道使用Php或Codeigniter发送表单的基本方法,但我不知道如何以HTML表单或Pdf格式发送表单。你是说通过电子邮件按原样发送表单 在laravel框架中,完全可以通过传入$view来发送视图(连同表单)。我不知道codeigniter,也许他们也有这种功能?如果我是你,我会使用,因为它有一个非常方便的接口,通过套接字支持不同的安全协议。如果你按照上面提到的链接,你会发现一个非常描述性的用法示例。现在,您要关注以下几行:如何通过php电子邮件发送填妥的表格,php,codeigniter,sendmail,Php,Codeigniter,Sendmail,我在我的网站上有一个用户填写的表单。在表单验证后,我想将该表单原样发送到邮件(可能是HTML表单或pdf)。我该怎么做?我知道使用Php或Codeigniter发送表单的基本方法,但我不知道如何以HTML表单或Pdf格式发送表单。你是说通过电子邮件按原样发送表单 在laravel框架中,完全可以通过传入$view来发送视图(连同表单)。我不知道codeigniter,也许他们也有这种功能?如果我是你,我会使用,因为它有一个非常方便的接口,通过套接字支持不同的安全协议。如果你按照上面提到的链接,你
<?php
$mail = new PHPMailer;
// [...]
$mail->IsHTML(true);
// [...]
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
?>
我打赌您可以将任何字符串传递给
Body
属性。因此,只需将填充有值的HTML表单呈现到一个变量中,然后将其传递给Body
这对于CI来说非常简单
您所要做的就是处理post,然后您可以创建一个新视图并将表单数据传递给它
$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();
试试这个:
#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();
}
}
更改邮件的标题,可以发送html邮件。这就是你想要的吗?->