我正在构建一个wordpress联系表单插件,该插件在使用短代码时输出一个简单的联系表单。短代码具有属性recipient_email
即用户希望所有电子邮件从表单转到的电子邮件地址。我正在尝试在我的 php 邮件程序中获取收件人电子邮件的值。
这是我的简码输出的带有其属性的 html:
extract(shortcode_atts(array(
'el_class' => '',
'title' => '',
'subtitle' => '',
'recipient_email' => '',
), $atts));
$el_class = $this->getExtraClass($el_class);
$css_class = apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG,$el_class, $this->settings['base']);
$subtitle = '<legend>'.$subtitle.'</legend>';
$output .= '<div class="contact-form '.$css_class.'" >';
$output .= '<h4 class="form-title">'.$title.'</h4>';
$output .= '<div id="contact">
<div id="message"></div>
<form method="post" action="'. VCPB_PLUGIN_URL . 'contact.php' .'" name="contactform" id="contactform">
<fieldset>';
$output .= $subtitle;
$output .= '<label for="name" accesskey="U"><span class="required">*</span> Your Name</label>
<input name="name" type="text" id="name" size="30" value="" />
<br />
<label for="email" accesskey="E"><span class="required">*</span> Email</label>
<input name="email" type="text" id="email" size="30" value="" />
<br />
<label for="phone" accesskey="P"><span class="required">*</span> Phone</label>
<input name="phone" type="text" id="phone" size="30" value="" />
<br />
<label for="comments" accesskey="C"><span class="required">*</span> Your message</label>
<textarea name="comments" cols="40" rows="5" id="comments" style="width: 350px;"></textarea>
<p><span class="required">*</span> Are you human?</p>
<label for="verify" accesskey="V"> 3 + 1 =</label>
<input name="verify" type="text" id="verify" size="4" value="" style="width: 30px;" /><br /><br />
<input type="submit" class="submit" id="submit" value="Submit" />';
$output .= '</fieldset>
</form>
</div>';
$output .= '</div>'; /* END .contact-form */
return $output;
如您所见,表单中的信息被发送到contact.php
处理表单并将其通过电子邮件发送出去。
这是我的 php 邮件程序文件 ( contact.php
的主要部分(:
$address = "$recipient_email";
$e_subject = 'You''ve been contacted by ' . $name . '.';
$e_body = "You have been contacted by $name, their message is as follows." . PHP_EOL . PHP_EOL;
$e_content = "'"$comments'"" . PHP_EOL . PHP_EOL;
$e_reply = "You can contact $name via email, $email or via phone $phone";
$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
这里的顶行是我试图解决的问题:
$address = "$recipient_email";
我希望$recipient_email
是输入到简码中的值。谁能告诉我我会怎么做?
两种方法要么通过隐藏的输入类型发送收件人(这不是一个好的选择(
或
将表单操作放在同一页面上,而不是联系人上.php在同一页面上,您可以使用shortcode_atts获取recipient_email