希望一切顺利。
我正在尝试向主页的某个部分添加自定义联系人表单。我在https://gist.github.com/hansspiess/6815875. 我在我的主页中实现了代码,以利用我正在使用的基于Zurb Foundation主题的自定义样式。表单似乎正在正确验证并提供适当的错误消息。“成功”提交后,我会收到一个成功警报,但实际上并没有收到管理员电子邮件地址的电子邮件。我还尝试在$mailto变量中手动插入其他电子邮件地址。我的希望是,我可能会错过一些明显的,任何帮助将不胜感激。
我的网站是ajinin.com
下面是我在上面放置的php逻辑<?php get_header(); ?>
:
<?php
/* response strings */
$missing_fields = \'Please fill out all fields.\';
$email_invalid = \'Your e-mail address is invalid.\';
$trapped = \'Please do not call this page via scripts.\';
$error = \'The message could not be sent.\';
$success = \'Thank you! The message has been sent\';
/* process post vars, leave honeypot raw */
$submitted = sanitize_text_field( $_POST[\'scf_submitted\'] );
$name = sanitize_text_field( $_POST[\'scf_name\'] );
$email = sanitize_text_field( $_POST[\'scf_email\'] );
$message = sanitize_text_field( $_POST[\'scf_message\'] );
$honeypot = $_POST[\'scf_message2\'];
/* wp_mail vars */
$mailto = get_option( \'admin_email\' );
$subject = \'Message from \' . get_bloginfo(\'name\');
$headers = \'From: \' . $email . "\\r\\n" . \'Reply-To: \' . $email . "\\r\\n";
if ( $submitted ) {
if ( $honeypot != "" ) {
scf_response("alert-danger", $trapped);
} else {
if ( !$name || !$email || !$message ) {
$alert[] = $missing_fields;
}
if ( !is_email( $email ) && $email ) {
$alert[] = $email_invalid;
}
if ( empty( $alert ) ) {
if ( wp_mail( $mailto, $subject, strip_tags( $message ), $headers ) ) {
$alert[] = $success;
scf_response("success", $alert);
unset( $submitted, $name, $email, $message, $honeypot );
} else {
$alert[] = $error;
scf_response("alert", $alert);
}
} else {
scf_response("warning", $alert);
}
}
}
/* output alert html */
function scf_response( $class, $alertArr ){
global $response;
$alertStr = implode( \'<br>\', $alertArr );
$response = \'<div data-alert class="alert-box \' . $class .\'">\' . $alertStr . \'<a href="#" class="close">×</a></div>\';
}
?>
以下是html表单:
<div class="grey">
<div class="row">
<div class="large-10 columns small-centered">
<h5>QUESTIONS OR COMMENTS? LET US KNOW.</h5>
<br>
<div class="row">
<div class="large-12 columns">
<?php echo $response ?>
</div>
</div>
<form role="form" action="<?php the_permalink(); ?>" method="post">
<div class="row">
<div class="large-6 columns">
<label for="scf_name" class="contact">Name</label>
<input
type="text"
id="scf_name" name="scf_name"
value="<?php echo $name; ?>">
</div>
<div class="large-6 columns">
<label for="scf_email" class="contact">Email</label>
<input
type="text"
id="scf_email" name="scf_email"
value="<?php echo $email; ?>">
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label for="scf_message" class="contact">Message</label>
<textarea
rows="4"
id="scf_message" name="scf_message"><?php echo $message; ?></textarea>
</div>
</div>
<div class="row" style="display:none">
<div class="large-12 columns">
<label for="scf_message2" class="contact">message2</label>
<input type="text" name="scf_message2" name="scf_message2">
</div>
</div>
<div class="row text-center">
<div class="large-12 columns">
<input type="hidden" name="scf_submitted" value="1">
<button type="submit" class="button medium blue">Send</button>
</div>
</div>
</form>
</div>
</div>
</div>
感谢您提供的任何帮助。如果有人有其他方法或知道他们信任的自定义联系人表单的教程,请告诉我。对我来说,最重要的是我可以很好地控制html/css结构。