FPDF를 사용하여 PDF 파일을 만들고 PHPMailer를 사용하여 전자 메일로 보내려고합니다. 그것은 파일을 보냈지 만 몇 가지 이유 때문에 이메일에서나 Adobe Reader를 사용하여 파일을 열 수 없습니다 (파일이 손상된 것처럼 보입니다).FPDF를 사용하여 이메일을 보낸 후 FPDF PDF 파일을 열 수 없습니다.
이 내가 $ PDF-를 사용할 때이> 나에게 문제가 FPDF 측에 안 나에게 힌트 출력() 출력을 제공 않습니다 내 코드
require('fpdf.php');
require 'PHPMailerAutoload.php';
header("Access-Control-Allow-Origin: *");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','UB',28);
$pdf->Cell(0,10,"My Profile",0,1,'C');
$pdf->Ln();
$mail = new PHPMailer();
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// main header
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
// no more headers after this, we start the body! //
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;
// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;
// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
$pdfdoc = $pdf->Output('','S');
$attachment = chunk_split(base64_encode($pdfdoc));
//Set who the message is to be sent from
$mail->setFrom('[email protected]', 'Baby Diary');
//Set who the message is to be sent to
$mail->addAddress('[email protected]', 'haha');
//Set the subject line
$mail->Subject = 'PHPMailer mail() test';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AddStringAttachment($attachment, 'doc.pdf', 'base64', 'application/pdf');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
입니다. 어떤 제안이라도 대단히 감사하겠습니다.
와우가이 방식으로 작동합니다 :
그래서 아래 코드 (난 당신이 아마 미세 조정이 필요합니다, 그것을 실행하지 않은) 같은 뭔가 끝낼 수 있습니다! 게다가, 나는 같은 시간에 내 서버에 저장할 수 있습니다! –