【问题标题】:Send Email fields not rendering in Sitecore Web Forms For Marketers发送电子邮件字段未在面向营销人员的 Sitecore Web 表单中呈现
【发布时间】:2014-09-02 15:11:51
【问题描述】:

我对 WFFM 发送电子邮件消息保存操作 (Sitecore 6.5.0) 有疑问。我正在尝试从发送电子邮件编辑器的“插入字段”下拉列表中发送包含表单占位符的电子邮件。有时字段会正确呈现,但大多数时候电子邮件会包含占位符文本而不是字段的实际值。

例如,这是通过的电子邮件:

First Name: [First Name] 
Last Name: [Last Name] 
Email: [Email Address] 
Company Name: [Company Name] 
Phone Number: [Phone Number] 

我认为这与使用电子邮件模板的富文本编辑器的发送电子邮件编辑器有关,但我尝试调整邮件的 HTML 无济于事。这就是标记的样子:(<p> 标签和标签曾经是内联的,但这也不起作用)

<p>First Name:
[<label id="{F49F9E49-626F-44DC-8921-023EE6D7948E}">First Name</label>]
</p>
<p>Last Name:
[<label id="{9CE3D48C-59A0-432F-B6F1-3AFD03687C94}">Last Name</label>]
</p>
<p>Email:
[<label id="{E382A37E-9DF5-4AFE-8780-17169E687805}">Email Address</label>]
</p>
<p>Company Name:
[<label id="{9C08AC2A-4128-47F8-A998-12309B381CCD}">Company Name</label>]
</p>
<p>Phone Number:
[<label id="{4B0C5FAC-A08A-4EF2-AD3E-2B7FDF25AFA7}">Phone Number</label>]
</p>

有谁知道可能出了什么问题?

【问题讨论】:

    标签: forms email sitecore sitecore6 web-forms-for-marketers


    【解决方案1】:

    我之前遇到过这个问题,但使用的是自定义电子邮件操作。我设法通过不使用 SendMail 类中已弃用的方法而是使用 Sitecore.Form.Core.Pipelines.ProcessMessage 命名空间的 ProcessMessageProcessMessageArgs 类。

    我的用例比你的要复杂一些,因为我们还在邮件中附加了 PDF 小册子(这就是我们首先使用自定义电子邮件操作的原因),但代码如下:

    public class SendBrochureEmail : SendMail, ISaveAction, ISubmit
    {
    
        public new void Execute(ID formId, AdaptedResultList fields, params object[] data)
        {
            try
            {
                var formData = new NameValueCollection();
    
                foreach (AdaptedControlResult acr in fields)
                {
                    formData[acr.FieldName] = acr.Value;
                }
    
                var senderName = formData["Your Name"];
                var emailTo = formData["Recipient Email"];
                var recipientName = formData["Recipient Name"];
    
                var documentTitle = formData["Document Title"];
                if (documentTitle.IsNullOrEmpty())
                {
                    documentTitle = String.Format("Documents_{0}", DateTime.Now.ToString("MMddyyyy"));
                }
                Subject = documentTitle;
    
                if (!String.IsNullOrEmpty(emailTo))
                {
                    BaseSession.FromName = senderName;
                    BaseSession.CatalogTitle = documentTitle;
                    BaseSession.ToName = recipientName;
    
                    var tempUploadPath = Sitecore.Configuration.Settings.GetSetting("TempPdfUploadPath");
                    var strPdfFilePath =
                        HttpContext.Current.Server.MapPath(tempUploadPath + Guid.NewGuid().ToString() + ".pdf");
    
                    //initialize object to hold WFFM mail/message arguments
                    var msgArgs = new ProcessMessageArgs(formId, fields, MessageType.Email);
    
                    var theDoc = PdfDocumentGenerator.BuildPdfDoc();
                    theDoc.Save(strPdfFilePath);
                    theDoc.Clear();
    
                    FileInfo fi = null;
                    FileStream stream = null;
                    if (File.Exists(strPdfFilePath))
                    {
                        fi = new FileInfo(strPdfFilePath);
                        stream = fi.OpenRead();
                        //attach the file with the name specified by the user
                        msgArgs.Attachments.Add(new Attachment(stream, documentTitle + ".pdf", "application/pdf"));
                    }
    
                    //get the email's "from" address setting
                    var fromEmail = String.Empty;
                    var fromEmailNode = Sitecore.Configuration.Factory.GetConfigNode(".//sc.variable[@name='fromEmail']");
                    if (fromEmailNode != null && fromEmailNode.Attributes != null)
                    {
                        fromEmail = fromEmailNode.Attributes["value"].Value;
                    }
    
                    //the body of the email, as configured in the "Edit" pane for the Save Action, in Sitecore
                    msgArgs.Mail.Append(base.Mail);
                    //The from address, with the sender's name (specified by the user) in the meta
                    msgArgs.From = senderName + "<" + fromEmail + ">";
                    msgArgs.Recipient = recipientName;
                    msgArgs.To.Append(emailTo);
                    msgArgs.Subject.Append(Subject);
                    msgArgs.Host = Sitecore.Configuration.Settings.MailServer;
                    msgArgs.Port = Sitecore.Configuration.Settings.MailServerPort;
                    msgArgs.IsBodyHtml = true;
    
                    //initialize the message using WFFM's built-in methods
                    var msg = new ProcessMessage();
                    msg.AddAttachments(msgArgs);
                    msg.BuildToFromRecipient(msgArgs);
                    //change links to be absolute instead of relative
                    msg.ExpandLinks(msgArgs);
                    msg.AddHostToItemLink(msgArgs);
                    msg.AddHostToMediaItem(msgArgs);
                    //replace the field tokens in the email body with the user-specified values
                    msg.ExpandTokens(msgArgs);
                    msg.SendEmail(msgArgs);
    
                    //no longer need the file or the stream - safe to close stream and delete delete it
                    if (fi != null && stream != null)
                    {
                        stream.Close();
                        fi.Delete();
                    }
                }
                else
                {
                    Log.Error("Email To is empty", this);
                    throw new Exception("Email To is empty");
                }
            }
            catch (Exception ex)
            {
                Log.Error("Test Failed.", ex, (object) ex);
                throw;
            }
            finally
            {
                BrochureItems.BrochureItemIds = null;
            }
        }
    
        public void Submit(ID formid, AdaptedResultList fields)
        {
            Execute(formid, fields);
        }
    
        public void OnLoad(bool isPostback, RenderFormArgs args)
        {
        }
    
    }
    

    WFFM 附带的电子邮件操作很可能正在使用已弃用的方法,这可能是您的问题。我没有时间研究它,但您可以反编译 DLL 并查看他们的电子邮件操作在做什么。无论如何,上面的代码应该开箱即用,除了将字段更新为您正在使用的字段并删除用于附加 PDF 的代码(如果您选择不包含附件)。

    祝你好运,编码愉快:)

    【讨论】:

      【解决方案2】:

      如果您以任何方式更改表单上的字段(captionnametype 等),链接将会更改,您需要重新插入占位符并将其移动到您预期的电子邮件。如果您复制表单,这也是正确的。您必须重新插入电子邮件中的所有字段,否则您只会得到上面显示的结果。

      在更改时重新插入将确保收集到值!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多