Reputation: 13344
I had been using PHP's in-built mail()
function to send a multi-part mail message with inline image. My client informs me they need to use authenticated SMTP to send mail, but they insist we cannot modify their server environment (thus I cannot configure PHP to use SMTP).
As such, I am now using the phpmailer class to send the message. All is working, EXCEPT for the embedded image. I have read the documentation and understand to embed an image, I simply call:
$mail->AddEmbeddedImage('path/to/image.jpg', 'CID_identifier');
Great, makes sense for most cases. BUT, the image I embed is not a static file on the server file system. It is rendered dynamically by a script that I have written, and captured within the email script through use of output butter:
ob_start();
require_once( '_gen_piechart.php' );
$base_64 = base64_encode( ob_get_contents() );
ob_end_clean();
Although I understand it may work, I do not wish to write the image to file, include in the outbound mail, and then unlink()
afterward.
Has anyone encountered this case before and come up with a solution for embedding image data? I do not see a phpmailer class method for embedding image data other than from the file system.
Upvotes: 0
Views: 1819
Reputation: 3352
AddStringEmbeddedImage is what you need. It allows adding the attachment from a string containing the image binary.
$mail->AddStringEmbeddedImage($fileContents, 'CID_identifier');
Upvotes: 5