Php 将已完成的PDF作为带有字段值的电子邮件附件发送

Php 将已完成的PDF作为带有字段值的电子邮件附件发送,php,forms,adobe,sendmail,Php,Forms,Adobe,Sendmail,我有一个在线PDF表单,用户完成后单击提交按钮,将表单作为附件发送到电子邮件地址,并将数据存储在数据库中。但是,发送到电子邮件地址时,不会显示已完成的单个字段值。我怎样才能做到这一点?非常感谢 //define the receiver of the email $to = 'test@*****.com'; //define the subject of the email $subject = 'Completed PDF form'; //create a boundary str

我有一个在线PDF表单,用户完成后单击提交按钮,将表单作为附件发送到电子邮件地址,并将数据存储在数据库中。但是,发送到电子邮件地址时,不会显示已完成的单个字段值。我怎样才能做到这一点?非常感谢

//define the receiver of the email 
$to = 'test@*****.com'; 
//define the subject of the email 
$subject = 'Completed PDF form'; 
//create a boundary string. It must be unique 
//so we use the MD5 algorithm to generate a random hash 
$random_hash = md5(date('r', time())); 
//define the headers we want passed. Note that they are separated with \r\n 
$headers = "From: noreply@test.com\r\nReply-To: noreply@test.com"; 
//add boundary string and mime type specification 
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; 
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents('purchase_order_form.pdf'))); 
//define the body of the message. 
ob_start(); //Turn on output buffering  
?> 
--PHP-mixed-<?php echo $random_hash; ?>  
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" 

--PHP-alt-<?php echo $random_hash; ?>  
Content-Type: text/plain; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit

Hello World!!! 
This is simple text email message. 

--PHP-alt-<?php echo $random_hash; ?>  
Content-Type: text/html; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit

--PHP-alt-<?php echo $random_hash; ?>-- 

--PHP-mixed-<?php echo $random_hash; ?>  
Content-Type: application/zip; name="purchase_order_form.pdf"  
Content-Transfer-Encoding: base64  
Content-Disposition: attachment  

<?php echo $attachment; ?> 
--PHP-mixed-<?php echo $random_hash; ?>-- 

<?php 
//copy current buffer contents into $message variable and delete current output buffer 
$message = ob_get_clean(); 
//send the email 
$mail_sent = @mail( $to, $subject, $message, $headers ); 
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed"; 
//定义电子邮件的收件人
$to='test@*****.com';
//定义电子邮件的主题
$subject='已填妥的PDF表格';
//创建一个边界字符串。它必须是独一无二的
//所以我们使用MD5算法来生成一个随机散列
$random_hash=md5(日期('r',时间());
//定义我们想要传递的标题。请注意,它们用分隔符分隔\r\n
$headers=“From:noreply@test.com\r\n适用于:noreply@test.com"; 
//添加边界字符串和mime类型规范
$headers.=“\r\n内容类型:多部分/混合;边界=\”PHP混合-“$random\u散列。”\”;
//将atachment文件内容读入字符串,
//用MIME base64对其进行编码,
//然后把它分成小块
$attachment=chunk\u split(base64\u编码(文件获取内容('purchase\u order\u form.pdf'));
//定义消息的主体。
ob_start()//打开输出缓冲
?> 
--PHP混合-
内容类型:多部分/备选;boundary=“PHP alt-”
--PHP alt-
内容类型:文本/纯文本;charset=“iso-8859-1”
内容传输编码:7bit
你好,世界!!!
这是一封简单的短信。
--PHP alt-
内容类型:text/html;charset=“iso-8859-1”
内容传输编码:7bit
--PHP alt--
--PHP混合-
内容类型:application/zip;name=“采购订单表单.pdf”
内容传输编码:base64
内容配置:附件
--PHP混合--

这是您使用的示例,您将看到它非常简单

require_once '/path/to/swift-mailer/lib/swift_required.php';

// Create the Transport
$transport = Swift_MailTransport::newInstance();

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

// Create the message
$message = Swift_Message::newInstance()

  // Give the message a subject
  ->setSubject($subject)

  // Set the From address with an associative array
  ->setFrom(array('noreply@test.com'))

  // Set the To addresses with an associative array
  ->setTo(array($to))

  // Give it a body
  ->setBody($message)

  // Optionally add any attachments
  ->attach(Swift_Attachment::fromPath('purchase_order_form.pdf'))
  ;

// Send the message
$result = $mailer->send($message);

echo $mail_sent ? "Mail sent" : "Mail failed"; 

这是您使用的示例,您将看到它非常简单

require_once '/path/to/swift-mailer/lib/swift_required.php';

// Create the Transport
$transport = Swift_MailTransport::newInstance();

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

// Create the message
$message = Swift_Message::newInstance()

  // Give the message a subject
  ->setSubject($subject)

  // Set the From address with an associative array
  ->setFrom(array('noreply@test.com'))

  // Set the To addresses with an associative array
  ->setTo(array($to))

  // Give it a body
  ->setBody($message)

  // Optionally add any attachments
  ->attach(Swift_Attachment::fromPath('purchase_order_form.pdf'))
  ;

// Send the message
$result = $mailer->send($message);

echo $mail_sent ? "Mail sent" : "Mail failed"; 

不要将mail()用于这种情况,它是非常有限的。什么是最好的方法?使用例如。不要将mail()用于这种情况,它是非常有限的。什么是最好的方法?使用例如。感谢您提供的代码片段!这是有效的,而且更干净,但是当我收到PDF附件时,我看不到完整的表单字段。有什么方法可以整合这一点吗?感谢基本上每个人都应该收到一份填好的表格,我怎样才能获取这些数据?谢谢。您想将表单中的数据转换成pdf格式并发送给客户吗?或者发送pdf,然后在邮件正文中,发送表单中的数据?嘿,我在AdobeReaderX中创建了一个在线表单。当用户填写表单时,它会被发送到包含表单数据(如姓名、地址等)的电子邮件地址。。我已使用上述代码将表单发送到一封电子邮件,该电子邮件正在工作,但查看时没有填写表单字段,它们显示为空白。感谢您提供的代码片段!这是有效的,而且更干净,但是当我收到PDF附件时,我看不到完整的表单字段。有什么方法可以整合这一点吗?感谢基本上每个人都应该收到一份填好的表格,我怎样才能获取这些数据?谢谢。您想将表单中的数据转换成pdf格式并发送给客户吗?或者发送pdf,然后在邮件正文中,发送表单中的数据?嘿,我在AdobeReaderX中创建了一个在线表单。当用户填写表单时,它会被发送到包含表单数据(如姓名、地址等)的电子邮件地址。。我已使用上述代码将表单发送到一封电子邮件,该电子邮件正在工作,但查看时没有填写表单字段,它们显示为空白。