我正在构建一个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
,contact.php
处理表单并通过电子邮件发送出去。
以下是我的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
我希望{{1}}成为输入短代码的值。任何人都可以告诉我如何做到这一点?
答案 0 :(得分:0)
有两种方法可以做到这一点 要么通过输入类型隐藏发送收件人(这不是一个好的选择)
或
将表单操作放在同一页面而不是contact.php上 在同一页面上,您可以使用shortcode_atts获取recipient_email