Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
501 views
in Technique[技术] by (71.8m points)

laravel - 将base64字符串转换为图像并使用laravel发送电子邮件(Converting base64 string into image and send in email using laravel)

I am using tinymce-vue editor to get the users information and laravel to store it.

(我正在使用tinymce-vue编辑器来获取用户信息并使用laravel进行存储。)

This information can be either regular text or images.

(此信息可以是常规文本或图像。)

The problem that I am experiencing is that because tinymce stores images as base64 I am unable to send users input in an email as is.

(我遇到的问题是,因为tinymce将图像存储为base64,所以无法按原样发送用户输入的电子邮件。)

For eg: If the user uploads an image inside tinymce, inserts additional content beneath the image and saves the information entered, this information is stored together inside a column, and then at an appointed time the information is sent out in an email.

(例如:如果用户在tinymce中上载图像,在图像下方插入其他内容并保存输入的信息,则此信息将存储在列中,然后在指定的时间通过电子邮件发送该信息。)

However, the email body displays the base64 string along with the other user information and html tags.

(但是,电子邮件正文将显示base64字符串以及其他用户信息和html标签。)

Is there a way to search the string for the base64 encoded data, retrieve it from the string, convert it into an image and replace the original base64 data with the actual image and send it via emal?

(是否可以在字符串中搜索base64编码的数据,从字符串中检索它,将其转换为图像并将原始的base64数据替换为实际图像并通过emal发送?)

I attempted to perform the task but the image does not appear within the email body.I'm using laravel Notifications

(我尝试执行任务,但是图像未出现在电子邮件正文中。我正在使用laravel通知)

在此处输入图片说明

  ask by user2538755 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What you are really asking here are two separate questions...

(您在这里真正要问的是两个独立的问题...)

  1. How do I take Base64 binary images from TinyMCE and store them in an appropriate format?

    (如何从TinyMCE中获取Base64二进制映像,并以适当的格式存储它们?)

  2. What is the best way to include images in an HTML email?

    (在HTML电子邮件中包含图像的最佳方法是什么?)

How do I take Base64 binary images from TinyMCE and store them in an appropriate format

(如何从TinyMCE中获取Base64二进制图像并将其以适当的格式存储)

TinyMCE has a built in mechanism to address this via its images_upload_url configuration option.

(TinyMCE具有内置的机制,可通过其images_upload_url配置选项解决此问题。)

There is an entire page in the TinyMCE documentation on how this works:

(TinyMCE文档中有一整页介绍了其工作原理:)

https://www.tiny.cloud/docs/advanced/handle-async-image-uploads/

(https://www.tiny.cloud/docs/advanced/handle-async-image-uploads/)

The net is that you can have TinyMCE send the image files to an endpoint of your choosing and then convert it to whatever format you need.

(最终,您可以让TinyMCE将图像文件发送到您选择的端点,然后将其转换为所需的任何格式。)

You don't need to keep it as a Base64 binary and it is very rare that you want the Base64 binary as the permanent format.

(您不需要将其保留为Base64二进制文件,并且很少希望将Base64二进制文件作为永久格式。)

As for the other question...

(至于另一个问题...)

What is the best way to include images in an HTML email?

(在HTML电子邮件中包含图像的最佳方法是什么?)

This is an incredibly broad topic on its own and there are a great many blog posts on the alternatives for how to include images.

(它本身就是一个令人难以置信的广泛话题,关于如何包含图像的替代方法有很多博客文章。)

This is an article that SendGrid wrote on the subject:

(这是SendGrid在该主题上写的一篇文章:)

https://sendgrid.com/blog/embedding-images-emails-facts/

(https://sendgrid.com/blog/embedding-images-emails-facts/)

As you can see there are multiple options each with pros and cons.

(如您所见,有多个选项各有利弊。)

Which one is right for your use case is not something I can tell you.

(我无法告诉您哪种适合您的用例。)

My advice would be to research the alternatives and select the one that works best for your application and the email clients you wish to support.

(我的建议是研究替代方案,然后选择最适合您的应用程序和希望支持的电子邮件客户端的方案。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...