开发者

email inline images in base 64 through email with php code igniter

I am generating images dynamically at run time with php and have them displayed in base 64 through the browser. This same page/html document I need emailed but this method to show images does not work through email.

I have found two code igniter libraries to try and help me with this task two of which do not work http://thecodeabode.blogspot.com/2010/11/codeigniter-and-php-howto-embedding.html

http://codeigniter.com/wiki/Richmail/

The first one gives me

Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

From: "SystemDDX" Return-Path: Reply-To: "internal-33e@google.com" X-Sender: internal-33ek@google.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <1d42c5c99deeb@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit

The second one is extremely outdated

The only method which I've managed to get working so far is using the code igniter $this->email->attach("C:\myfile.jpg") and then in my html refere开发者_如何学编程nce using <img src='cid:myfile.jpg' />

The problem is my image is in base64 as I'm generating it dynamically so if I can't figure out anything else, how can I revert base 64 to a specific file name while keeping it in memory.

Please any tips and help would be greatly appreciated


The only method which I've managed to get working so far is ... <img src='cid:myfile.jpg' />

Good, because that's the way it should be done. As you have discovered, inlined base64 images are very poorly supported outside of bleeding-edge browsers.

The problem is my image is in base64 as I'm generating it dynamically so if I can't figure out anything else, how can I revert base 64 to a specific file name while keeping it in memory.

Well, how are you converting that image to base64 to begin with? You're certainly using base64_encode on the image's data, right?

Well then, don't do that!

Instead, write the image data to a new file on disk, and then reference that new image file when attaching it to the outgoing mail. Problem solved!

This assumes that the attachment method in your chosen email library only accepts real files -- read the docs, I'll bet that you can pass the image data directly and give it a "fake" file name at the same time.

You might want to consider using another modern mail library, like SwiftMailer. It can attach dynamic content smoothly and easily.


I'm generating sparklines graphics dynamically and using this to get the content:

function OutputToDataURI() {
    ob_start(NULL,4096);
    $this->Output();
    header('Content-type: text/html');
    return "data:image/png;base64,".base64_encode(ob_get_clean());

}

In that case, this will get your raw image data:

public function GetImageData() {
    ob_start();
    $this->Output();
    return ob_get_clean();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜