我正在構建一個wordpress聯繫表單插件,當使用短代碼時,它可以輸出一個簡單的聯繫表單。短代碼的屬性recipient_email
這是用戶希望所有電子郵件從表單轉到的電子郵件地址。我正在嘗試在我的PHP郵件程序文件中獲取收件人電子郵件的值。WordPress的從一個頁面內的短代碼獲取屬性
這是我的簡碼輸出的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
是輸入到簡碼中的值。任何人都可以幫我弄清楚我該怎麼做?
那麼您是否創建了這個簡碼?你用來從短代碼輸出html的代碼在哪裏? – manishie 2014-09-30 00:42:44
@manishie只是在我的問題中添加了整個簡碼代碼。謝謝 – 2014-09-30 07:27:29