PHP - 将生成的图像从外部文件嵌入到HTML电子邮件中 [英] PHP - Embed Generated Image from External File into HTML email

查看:139
本文介绍了PHP - 将生成的图像从外部文件嵌入到HTML电子邮件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个注册表格。当有人注册时,他们会立即收到一封电子邮件(HTML格式),其中包含以下信息:



1)他们的注册信息(姓名,P#,电子邮件,等等)



我需要的是以下内容:



1)注册后,在电子邮件中用户接收,需要由外部脚本生成的png图像。目前,我正在使用PEAR生成/发送电子邮件(AOK)和Mail_Mime :: addHTMLImage()来添加图像,但唉,没有运气。当我发送电子邮件时,我得到的是一个破碎的图像,我的alt文字出现。重要的是要记住,我正在从外部脚本生成图像(用于HTML电子邮件)。



我正在使用的代码抓取图像(从外部脚本)如下所示:

  $ mime-> addHTMLImage(get_template_directory_uri() qr_code_generator.php?code =,image / png); 

另外,不确定是否有帮助,但我使用 http://phpqrcode.sourceforge.net/ 为QR码生成



任何和所有的帮助非常感谢!

解决方案

我在以前的问题 here



可能的问题是,您无法将base64编码的图像直接嵌入电子邮件的正文,您必须将其视为附件。您的方式是使用内容部分和适当的内容ID。



查看addHTMLImage方法的文档。
https://pear.php。 net / manual / en / package.mail.mail-mime.addhtmlimage.php



这不是最好的文档,但检查出来,我的其他答案。这应该足以解决问题。


I have a sign-up form. When someone signs up, they immediately receive an email (in HTML format) with the following information:

1) Their sign-up information (Name, P#, Email, etc.)

What I need is the following:

1) After sign-up, in the email the user receives, there needs to be a png-image that is generated by an external script. At the moment, I am using PEAR to generate/send the email (AOK) and Mail_Mime::addHTMLImage() to add the image, but alas, with no luck. All I get when I send the email is a broken image with my alt text appearing. It's important to keep in mind that I am generating the image (to be used in the HTML email) from an external script.

The code I'm using to try and grab the image (from the external script) is as follows:

$mime->addHTMLImage(get_template_directory_uri()."/qr_code_generator.php?code=", "image/png");

Also, not sure if it helps, but I'm using http://phpqrcode.sourceforge.net/ for the QR code generation

Any and all help is greatly appreciated!

解决方案

I answered most of this in your previous question here.

The likely issue again is that you can't embedded base64 encoded images directly into the body of the email, you have to treat them like attachments. The way you do that is with a content section and an appropriate content id.

Check out the documentation for the addHTMLImage method. https://pear.php.net/manual/en/package.mail.mail-mime.addhtmlimage.php

It's not the best documentation but check it out and my other answer. That should give you enough to solve the issue.

这篇关于PHP - 将生成的图像从外部文件嵌入到HTML电子邮件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆