我正在使用Laravel发送电子邮件,纯文本效果很好.但是,我在将图像附加到电子邮件时遇到问题.到目前为止,图像已作为Base64字符串存储在数据库中.
I am using Laravel to send emails and plain text works fine. However, I am having an issue attaching images to the email. As of right now, images are stored in the DB as Base64 Strings.
这是在Laravel中调用Mail门面的代码:
This is the code that calls the Mail facade in Laravel:
Mail::queue('emails.infraction', $data, function($message) use ($email){ $message -> from($fromEmail, 'Blah); $message -> to($toEmail) -> subject('Testing'); });基本上,$ data变量包含我将在发送的HTML电子邮件中显示的所有信息.在电子邮件中显示变量时,我可以很好地访问变量,但是在将base64图像附加到电子邮件中时遇到问题.
Basically the $data variable contains all the information I will be displaying in the HTML email that is being sent. I can access the variables just fine when displaying them in the email but I am having issues attaching the base64 images into the email.
这是我到目前为止尝试过的:
This is what I have tried so far:
Evidence of Intraction:</p> <?php $elementCount = count($photos); for($x=0; $x<$elementCount; $x++){ echo '<p style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; margin-left: 80px;">'; echo "<img src=" . $message->embedData($data['photos'][$x], 'Blah') . ">"; echo "</p>"; } ?>但是正如您在此处看到的,gmail无法将rawDataString正确编码为图像:
But as you can see here, gmail does not properly encode that rawDataString into the image:
它只是显示好像有图片,而不显示内容.我已经验证了基本的64位字符串,它是正确的.
It just displays as if a picture was there but not the contents. I have verified the base 64 string and it is correct.
可能是什么错误?
Laravel邮件文档说在消息生成器中使用以下内容:
Laravel Mail Documentation says to use something like this in the message builder:
但是我对如何正确地执行操作有些迷茫.另一个选择是将base64字符串即时转换为图像并将其作为附件发送给用户,但是我无法将图像存储到服务器中,因此必须将其转换为php中的图像并通过发送没有实际文件路径的laravel mailer.
but I am a little lost on how to do that properly. The other option would be to convert the base64 string into an image on the fly and send it as an attachment to the user but I cannot store the images into the server and thus would have to convert it to an image within php and sending it through laravel mailer without an actual filepath.
请告知
推荐答案您必须先对图像进行解码,如下所示:
You have to decode the image first like this:
$message->embedData(base64_decode($data['photos'][$x]), 'Blah')更多推荐
使用Laravel发送Base64图像
发布评论