【问题标题】:How to add a variable from input field to the mail subject?如何将输入字段中的变量添加到邮件主题?
【发布时间】:2015-05-28 08:05:20
【问题描述】:

我正在使用联系表单工具从输入表单数据发送电子邮件。

该工具会使用文本和输入字段“名称”中的数据自动设置主题。我想将输入“代码”中的数据添加到主题中。

设置主题的函数:

 function SendFormSubmission()
{
    $this->CollectConditionalReceipients();

    $this->mailer->CharSet = 'utf-8';

    $this->mailer->Subject = "$code $this->code $this->name";

    $this->mailer->From = $this->GetFromAddress();

    $this->mailer->FromName = $this->name;

    $this->mailer->AddSubject= $this->code;

    $this->mailer->AddReplyTo($this->email);

    $message = $this->ComposeFormtoEmail();

    $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
    $this->mailer->AltBody = @html_entity_decode($textMsg,ENT_QUOTES,"UTF-8");
    $this->mailer->MsgHTML($message);

    $this->AttachFiles();

    if(!$this->mailer->Send())
    {
        $this->add_error("Failed sending email!");
        return false;
    }

    return true;
}

它不会从代码输入中添加数据。

整个项目: https://ide.c9.io/rokas_m/contactform_php

【问题讨论】:

  • 请显示更多代码。你在哪里设置$code$this-&gt;code
  • 整个项目都在这里:ide.c9.io/rokas_m/contactform_php 我是这样设置的:function GetCode() { return $this->code; }
  • 需要登录和注册。
  • 你能告诉我应该如何设置$code吗?我有
  • 您可能想从找出 $code 或 $this -> 代码是否有任何内容开始。试试简单的print $code 看看里面有没有东西。

标签: php email variables phpmailer


【解决方案1】:
  1. 转到函数:function CollectData(){}

  2. 在新行中写入此函数: $this-&gt;code = $this-&gt;Sanitize($_POST['code']);

  3. 转到$this-&gt;mailer-&gt;Subject = "$code $this-&gt;code $this-&gt;name"; 并删除"$code"

最好显示所有代码,即使它是从互联网复制/粘贴的。它会帮助我们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    • 2022-11-20
    • 1970-01-01
    • 2018-06-11
    相关资源
    最近更新 更多