如何创建电子邮件回复/编码回复的方法?

编程入门 行业动态 更新时间:2024-10-24 06:34:11
本文介绍了如何创建电子邮件回复/编码回复的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在构建一个代表我的应用程序用户回复电子邮件的应用程序.这些电子邮件将发送给我的用户,并被我的应用拦截,以自动回复他们的客户.这些电子邮件来自第三方,并且包含品牌格式.

I'm building an app which responds to emails on behalf of my app users. These emails are sent to my users and intercepted by my app to auto-respond to their clients. The emails come from third parties and contain branded formatting.

我的PHP应用程序获取电子邮件的完整HTML,将其存储在MySQL表中,然后创建回复,并将HTML附加在电子邮件底部的< hr/> 下.

My PHP app takes the full HTML of the email, stores it in a MySQL table then creates a reply and appends the HTML under a <hr/> at the bottom of the email.

这有效并且看起来像是答复(这是我的意图(尽管我将构建一些标头详细信息以使其看起来更加合法,就像在Outlook或类似程序中已回复).

This works and it looks like a reply (which is my intention (although I will build some header detail to make it look more legitimate as if it was replied to in Outlook or similar)).

但是,我的问题是,此方法损害了回复的格式-似乎采用了回复底部原始电子邮件HTML中的行高等样式.

My problem, however, is that this method hurts the reply formatting - it seems to take on styles like line-height from the original email HTML at the bottom of the reply.

因此,我的问题是,如何创建回复电子邮件?做我正在做的事情并更好地设置回复的样式,或者我需要对完整的原始内容做更多的工作,而不仅仅是HTML输出.并且甚至可以在电子邮件中使用HTML标签吗?

Thus my question is, how do I create a reply email? Do do what I'm doing and style my reply better, or do I need to do more with the complete original, not just the HTML output. And is it even ok to have to HTML tags in an email?

如果答案是这样,我会喜欢的:从电子邮件中提取X并使用开源Y库建立回复:)

I would love it if the answer was something like: extract the X from the email and build a reply with the opensource Y library :)

按要求发送电子邮件示例

此第三方电子邮件的标题如下:

This third party email contains a head that looks like this:

<html> <head> <style type='text/css'> body{font-family: arial,helvetica,sans-serif;} a{color: #06c;} p{margin:0;} #message{width:600px;margin:0 auto;} .legal{margin-top:2em;} .footer{margin-top:1em;padding:5px;background:#999999;color:#fff;} .footer a{color:#fff;} .senderName,.label{font-weight:bold;} .link,.label,.hint{margin-top: 20px;} .header-separator{height:4px;background-color:#e4002b;width:100%;margin-top:17px;} tr,td{vertical-align:top;text-align:left;} img{border:0;} ${css!""} </style> </head> <body> <div id='message'> ...

我的用户电子邮件模板(内置于TinyMCE中)将如下所示:

And my user email templates (built in TinyMCE) will look something like this:

<p><span style="font-family: Calibri, sans-serif; font-size: 11pt; line-height: 14pt;">Dear [name],</span></p> <p><span style="font-family: Calibri, sans-serif; font-size: 11pt; line-height: 14pt;">Thanks for your enquiry ...

当我将电子邮件发送到电子邮件服务时,很简单:

When I send the email to the email service it's as simple:

$emailreply = $userTemplate . '<hr/>' . $originalEnquiry;

当然,这还不够吗?另外,这是我提到的电子邮件,其中行高度受到影响-因此我的用户模板未按设计发送.

Surely, that's not good enough? Also, this is the email that I mentioned where line-height is being affected - so my user templates are not sending as designed.

推荐答案

在第三方电子邮件中,这种情况有点稀有,具有< style> 标记HTML电子邮件开发的通常过程是内联设置所有样式.

It's kinda rare the case on the 3rd party email, having separated <style > tag when the usual procedure on HTML email development is to set up all styles inline.

有点逻辑,这些样式(来自< style> 标记正在破坏您的新代码,此处的最佳选择是使所有样式(第3方电子邮件)内联,因此您可以删除< style> 标记,同时将两种电子邮件样式分开.

It's kinda logical that those styles (from the <style > tag are damaging your new code, The best option here is to make all that styling (from the 3rd party email) inline, so you can remove the <style > tag, keeping both email styling separated.

正如您所说的 PHP应用,我认为您可以使用以下某些功能:

As you said PHP App, I think you can use some of the following:

  • github/tijsverkoyen/CssToInlineStyles
  • github/jjriv/emogrifier
  • github/emilsundberg/Laravel-HTML-email-inliner/blob/master/src/Emil/Inliner/vendor/Premailer/Premailer.php

并确保,如果上述工具中的所选工具没有删除< style> ...</style> 标记,请自行删除(您可以这样做)使用正则表达式).

And make sure, if the chosen one of the above tools doesn't remove the <style>...</style> tag, remove it by yourself (you can do it using regular expressions).

希望这会有所帮助,祝你好运

Hope this helps, good luck

更多推荐

如何创建电子邮件回复/编码回复的方法?

本文发布于:2023-10-29 10:16:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539431.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电子邮件   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!