因此,我已将联系表单放入我的网站中,但我似乎无法添加主题行。 (我对 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->AddSubject('Website Communication:');
段,但它似乎不起作用,我想知道是否缺少某些内容?
最佳答案
您真正要问的是如何使用您从互联网下载的特定库类!如果您查看顶部包含的类的代码(我假设它与 this 相同?),那么您会看到它在此处自动生成主题行:
$this->mailer->Subject = "Contact form submission from $this->name";
您的 AddSubject
函数不起作用的原因是类中不存在该行为。
如果你想改变这种行为,你必须改变类。您需要将上面的行更改为类似
$this->mailer->Subject = $this->getSubject();
并实现一个 getSubject()
方法,类似于 GetFromAddress()
方法。
更好的是,创建您自己的邮件程序类!查看PHP mail function开始吧!
关于php - 向 PHP 表单添加主题行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33483780/