【问题标题】:Adding a subject line to PHP form向 PHP 表单添加主题行
【发布时间】:2016-02-02 16:48:06
【问题描述】:

所以我已经在我的网站中添加了一个联系表单,但我似乎无法添加主题行。 (我是 PHP 的超级新手,所以我对自己在做什么只有大约 40% 的把握。其余时间我只是通过反复试验来学习)。

这是我的表格:

<?PHP
require_once("./include/fgcontactform.php");

$formproc = new FGContactForm();

$formproc->AddRecipient('email address');
$formproc->AddSubject('Website Communication:');

$formproc->SetFormRandomKey('boQQEtSLenwppBa');


if(isset($_POST['submitted']))
{
   if($formproc->ProcessForm())
   {
        $formproc->RedirectToURL("thank-you.php");
   }
}

?>

<!-- Form Code Start -->
<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
<fieldset >
<legend>Contact us</legend>

<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text'  class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />

<div class='short_explanation'>* required fields</div>

<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
<div class='container'>
    <label for='name' >Your Full Name*: </label><br/>
    <input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
    <span id='contactus_name_errorloc' class='error'></span>
</div>
<div class='container'>
    <label for='email' >Email Address*:</label><br/>
    <input type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
    <span id='contactus_email_errorloc' class='error'></span>
</div>

<div class='container'>
    <label for='message' >Message:</label><br/>
    <span id='contactus_message_errorloc' class='error'></span>
    <textarea rows="10" cols="50" name='message' id='message'><?php echo $formproc->SafeDisplay('message') ?></textarea>
</div>


<div class='container'>
    <input type='submit' name='Submit' value='Submit' />
</div>

</fieldset>
</form>

我添加了 $formproc-&gt;AddSubject('Website Communication:'); 部分,但它似乎不起作用,我想知道我是否遗漏了什么?

【问题讨论】:

  • 您用来发送电子邮件的框架/工具不是标准的 PHP 方式。制作“fgcontactform”的人应该有文档告诉你如何做到这一点。你有他们网站的链接吗?

标签: php forms contact


【解决方案1】:

您真正要问的是如何使用您从 Internet 下载的特定库类!如果您查看您包含在顶部的类的代码(我假设它与 this 相同?)然后您会看到它在这里自动生成主题行:

$this->mailer->Subject = "Contact form submission from $this->name";

AddSubject 函数不起作用的原因是该行为在类中不存在。

如果你想改变这种行为,你必须改变类。您需要将上面的行更改为类似

$this->mailer->Subject = $this->getSubject();

并实现getSubject() 方法,类似于GetFromAddress() 方法。

更好的是,创建您自己的邮件程序类!查看PHP mail function 开始使用!

【讨论】:

  • 是的,我从一个网站上提取了联系表,以了解如何让这一切正常工作。我没有意识到它已经在自己创建一个。非常感谢您的解释(以及该链接)。我真的很感谢耐心和鼓励! :)
  • 你回答的最后一部分没有任何意义......当有可以管理 cc/bcc/atachments/smtp 连接的库时,他为什么要创建自己的包装器/库/等等……给你?
  • 作为学习练习。另外,当你在称呼一个你不知道性别的人时,使用非性别特定的代词是有礼貌的。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-12
  • 1970-01-01
  • 1970-01-01
  • 2012-01-31
相关资源
最近更新 更多