FPDF를 사용하여 PDF를 생성하므로이를 고객에게 이메일로 보내야합니다.PHP 파일을 만들지 않고 첨부 파일이있는 이메일을 보내시겠습니까?
DB에서 PDF를 생성 할 수 있으므로 모든 PDF가 로컬로 저장되지 않으므로 서버가 복잡해집니다.
PDF가 첨부 된 이메일을 보내려합니다. 임시 파일을 만든 다음 매번 삭제하거나 다른 방법으로 파일을 만들어야합니까?
FPDF를 사용하여 PDF를 생성하므로이를 고객에게 이메일로 보내야합니다.PHP 파일을 만들지 않고 첨부 파일이있는 이메일을 보내시겠습니까?
DB에서 PDF를 생성 할 수 있으므로 모든 PDF가 로컬로 저장되지 않으므로 서버가 복잡해집니다.
PDF가 첨부 된 이메일을 보내려합니다. 임시 파일을 만든 다음 매번 삭제하거나 다른 방법으로 파일을 만들어야합니까?
<?php
//define the receiver of the email
$to = '[email protected]';
//define the subject of the email
$subject = 'Test email with attachment';
//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: [email protected]\r\nReply-To: [email protected]";
//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('attachment.zip')));
//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
<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>
--PHP-alt-<?php echo $random_hash; ?>--
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: application/zip; name="attachment.zip"
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";
?>
이 라인 $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip')));
을 알 당신은 메모리 파일에 맞게 변경합니다.
확실히 가능합니다. 첨부 파일을 처리 할 수있는 PHP 메일러 클래스를 가져 와서 파일에서 데이터를 읽는 대신 addAttachment
함수를 다시 작성하여 대신 변수를 사용할 수 있습니다.
Zend_Mail은 문자열을 직접 다시 첨부하지 않고 직접 첨부 파일로 소화 할 수있는 것처럼 보입니다.
흥미로운 ... 정말 고마워! FPDF가 파일에 쓰는 것이 아니라 문자열을 반환 할 수 있다는 것을 알게되었습니다 : http://www.fpdf.org/en/doc/output.htm 사용 하시겠습니까? – Samuurai
그건 좋은 소리. – Pentium10