我剛剛遇到了一個問題,當從服務器發送附件大於約2.5Mb的郵件。發送附件較小的電子郵件可以工作,但一旦達到2或2.5Mb的關鍵尺寸,郵件就不會再發送了。發送郵件大附件 - ZF2
無論大小如何,都可以創建PDF文件和合並的目標PDF。但只有較小的PDF文件是通過郵件發送的。當附件太大時,甚至不會發送空郵件。
該過程如下:
1)php腳本創建幾個PDF文件。
2)的那些文件是通過GS
$finCmd = 'gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile='.$pathDest.$pdfFilename.' input1.pdf input2.pdf input3.pdf';
// Create PDF
$execResult = exec($finCmd);
3)電子郵件主體創建
protected function setBodyHtmlpart($content, $pdfFilepath = null, $pdfFilename = null) {
$content="<p><span style='font-size:10.0pt;font-family:\"Arial\",\"sans-serif\";color:black;'>".$content.'</span></p>';
$html = new MimePart($content.$this->getSignature());
$html->type = "text/html";
$body = new MimeMessage();
if ($pdfFilename != '') {
$pdfAttach = new MimePart(file_get_contents($pdfFilepath.$pdfFilename));
$pdfAttach->type = 'application/pdf';
$pdfAttach->filename = $pdfFilename;
$pdfAttach->encoding = \Zend\Mime\Mime::ENCODING_BASE64;
$pdfAttach->disposition = \Zend\Mime\Mime::DISPOSITION_ATTACHMENT;
$body->setParts(array($html, $pdfAttach));
} else {
$body->setParts(array($html));
}
return $body;
}
4)合併的電子郵件是發送:
protected function send($fromAddress, $fromName, $toAddress, $toName, $subject, $bodyParts)
{
// setup SMTP options
$options = new SmtpOptions(array(
'name' => 'XServer',
'host' => 'xServer',
'port' => 25,
'connection_class' => 'plain',
'connection_config' => array(
'username' => 'Xusername',
'password' => 'Xpassword',
),
));
$mail = new Message();
$mail->setBody($bodyParts);
$mail->setFrom($fromAddress, $fromName);
$mail->setTo($toAddress, $toName);
$mail->setSubject($subject);
$transport = new SmtpTransport($options);
$transport->send($mail);
}
任何提示是受歡迎的,因爲我完全失去了。
我以爲可能會出現種族問題:exec沒有完成,但腳本已經嘗試發送郵件並取消。但我至少會收到一封空郵件。
編輯: 更改然後Mime \ Mime :: ENCODING_BASE64提供郵件,但PDF文件已損壞。
你確定生成的PDF文件實際上是罰款嗎?你生成並打開了一個? – Andrew
是的。我打開生成的文件,他們是正確的。而不是那些解碼不正確,請參閱我的答案。 –