Problems with email when generating a HTML body and a PDF attachment

Viewed 114

I am hoping someone out there can help me with this issue I've been battling for far too long on.

I have a business-to-consumer (B2C) sales portal that was running Ubuntu 16.04 and PimCore 4.6, to which, everything worked. Emails with sales receipts attached were being sent out without any issue. However, a company security audit noticed that the version of Ubuntu had run out of its security updates and as such, needed updating.

Therefore I updated the OS from 16.04 to 18.04 and after a little trouble getting PHP to be set upon version 7.0.33, everything worked within the B2C portal, or so I thought. When I tried a test transaction, I found that the email functionality no longer worked. Cutting a long story down, the precise issue was that when I attached a generated sales PDF, the email->send() function, no longer worked and the website was issuing an HTTP code 503.

The PDF function works still, as I amended the code to store the PDF as a file, along with returning it as a string to be attached within the email as an attachment.

$pdf->Output('/var/www/html/Receipt_'.$varArray['order']['referenceNo'].'.pdf', 'F');          
return $pdf->Output('/var/www/html/Receipt_'.$varArray['order']['referenceNo'].'.pdf', 'S');

The email function, I have simplified:

// Construct the mail object and send the mail.
$mail = new \Pimcore\Mail('UTF-8');

$mail->setSender($this->email);
$mail->setFrom($this->email);
$mail->addTo($this->metadata["email address"]);

$mail->setSubject($this->view->translate("order confirmation", $this->zendLocale)." : ".$this->metadata["order number"]);

// Generate the HTML body of the email.
$mail->setDocument($this->emailPath.'neworder');
$mail->setParams($params);

// Build the PDF.
// If I comment out this line, the email gets sent.
$mailContent = $this->generateSalesReceipt($params, $orders);

$mail->send();

The line $mailContent takes the PDF generated and holds it as a string, in this instance, it doesn't do anything else with it, but that is enough to prevent the mail from being sent.

However, if I comment out the two lines which generate the HTML body of the email, I can happily attach the PDF to the email. It seems to be a clash between the generation of the HTML body and the PDF attachment.

I've added the below lines in order to see any issue with PHP as to why it is failing on me,

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

But none are explaining why the code is not working. I've checked all of the log files that I can find, which may say something about this, but the likes of Syslog, apache2 log and PHP log do not give anything away.

As I've said, this has only occurred with the change from OS16.04 to OS18.04 and PHP 7.0.28 to PHP 7.0.33. This as you can imagine is so frustrating, to be so close to having the server up and running 100% or to possibly looking at having to revert to a snapshot before I performed the OS upgrade and undoing all of my work.

Any help given that leads to a fix, there will be a coffee or bottle of beer waiting for the lucky person.

1 Answers

The only way I could get around this seemingly impossible situation was to create an email object, generate the PDF to a variable, destroy and then create a new email object, using the HTML generated in the first email to populate the second email object.

Related