Email filled PDF with PHP or PHPMailer

倖福魔咒の 提交于 2019-12-11 12:38:31

问题


My company is currently trying to streamline our process for submitting forms. I have read that what we are trying to do can be done with PHP or PHPMailer but I seem to have hit a roadblock.

What we are trying to do is open a fillable PDF in browser, complete it, and then click a button at the bottom to email it to a designated recipient.

I currently have a PHP script that allows me to email the blank document using PHPMailer and our server email service.

I have tried using the "AddStringAttachment" feature of PHPMailer:

<?php

require("../PHPMailer_5.2.3/class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();  // telling the class to use SMTP
$mail->Host     = "xxx.xxx.org"; // SMTP server

$mail->From     = "xxx@xxx.org";
$mail->AddAddress("xxx@xxx.org");

$mail->Subject  = "Attachment Test";
$mail->Body     = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
$mail->AddStringAttachment($string,'filename.pdf');

if(!$mail->Send()) {
  echo 'Message was not sent.';
  echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo 'Message has been sent.';
}
?>

...but I was unable to find a way to define the string in a way that would send the completed form. Currently, if I put any data into the "$string" field the email fails.

Is this even possible? Or am I just spinning my wheels?


回答1:


The problem might be with your mail server. Many servers don't like sending corrupted PDFs, which would be any PDF that doesn't look like a normal PDF - say, a string of English text.

Are you able to send any other kind of attachment, before I get into how to generate a PDF in PHP?



来源:https://stackoverflow.com/questions/14967147/email-filled-pdf-with-php-or-phpmailer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!