I am trying to create a file using dompdf and attach it to mime without saving. I got the answer from https://stackoverflow.com/a/12008553/9727103, so I used it but email contains something not expected.
This is my partial code.
$pdf = $dompdf->output();
$mm = new Mail_mime();
$msg = 'Hello world to all.';
$mm->setTxtBody($msg);
$mm->addAttachment($pdf,'application/pdf','output.pdf', false);
$body = $mm->get();
$subject = 'Hello World - ['.$customer.']';
$recipients = 'a@b.com';
$headers['From']= 'ab@bc.com';
$headers['To']= 'a@b.com';
$headers['Subject'] = $subject;
$params['host'] = 'smtp.sendgrid.net';
$params['port'] = '587';
$params['auth'] = true;
$params['username'] = 'my@user.name';
$params['password'] = 'my@user.pass';
$mail_object = Mail::factory('smtp', $params); // Print the parameters you are using to the page
// Send the message
$mail_object->send($recipients, $headers, $body);
if (PEAR::isError($mail_object)) {
echo("<p>" . $mail_object->getMessage() . "</p>");
} else {
echo("Message sent!");
}
It sends successfully but the email I received is this.
--=_0db58b483b7f7e450132520a9d0c50fe
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1
Hello World to all.
--=_0db58b483b7f7e450132520a9d0c50fe
Content-Transfer-Encoding: base64
Content-Type: application/pdf;
name=output.pdf
Content-Disposition: attachment;
filename=output.pdf;
size=5444
JVBERi0xLjMKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZwovT3V0bGluZXMgMiAwIFIKL1BhZ2Vz
IDMgMCBSID4+CmVuZG9iagoyIDAgb2JqCjw8IC9UeXBlIC9PdXRsaW5lcyAvQ291bnQgMCA+Pgpl
bmRvYmoKMyAwIG9iago8PCAvVHlwZSAvUGFnZXMKL0tpZHMgWzYgMCBSCl0KL0NvdW50IDEKL1Jl
c291cmNlcyA8PAovUHJvY1NldCA0IDAgUgovRm9udCA8PCAKL0YxIDggMCBSCi9GMiA5IDAgUgo+
PgovWE9iamVjdCA8PCAKL0kxIDE0IDAgUgo+PgovRXh0R1N0YXRlIDw8IAovR1MxIDE1IDAgUgov
R1MyIDE2IDAgUgo+Pgo+PgovTWVkaWFCb3ggWzAuMDAwIDAuMDAwIDYxMi4wMDAgNzkyLjAwMF0K
ID4+CmVuZG9iago0IDAgb2JqClsvUERGIC9UZXh0IC9JbWFnZUMgXQplbmRvYmoKNSAwIG9iago8
PAovUHJvZHVjZXIgKP7/AGQAbwBtAHAAZABmACAAKwAgAEMAUABEAEYpCi9DcmVhdGlvbkRhdGUg
....
Attached file is converted to string and there is
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1
Which I didn't intend. When I use https://www.freeformatter.com/base64-encoder.html#ad-output and copy the pdf string and click 'decode and download' it downloads the pdf file I attached, but I want it to be a just regular email with the attached file.
Is there any way I could resolve this problem? Any help will be appreciated. Thanks!