WordPress PHP表单赢得';不发送
我可能在这里遗漏了一些非常简单的东西,或者代码中有一点输入错误,但是我为正在构建的WordPress站点创建的PHP表单不会发送。如果表单中有错误,则验证有效(除非您只是输入一个名称),但当您正确填写表单并单击“提交”时,它只会转到要处理的页面,并说“对不起,没有符合您标准的帖子。”。再加上邮件无法发送 编辑 开发人员站点的链接是 要处理的页面不存在。这是我的密码: 表格代码WordPress PHP表单赢得';不发送,php,forms,wordpress,email,Php,Forms,Wordpress,Email,我可能在这里遗漏了一些非常简单的东西,或者代码中有一点输入错误,但是我为正在构建的WordPress站点创建的PHP表单不会发送。如果表单中有错误,则验证有效(除非您只是输入一个名称),但当您正确填写表单并单击“提交”时,它只会转到要处理的页面,并说“对不起,没有符合您标准的帖子。”。再加上邮件无法发送 编辑 开发人员站点的链接是 要处理的页面不存在。这是我的密码: 表格代码 <form name="quick-contact" class="quick-contact" method="
<form name="quick-contact" class="quick-contact" method="post" action="<?php bloginfo('url'); ?>/get-in-touch/">
<h3>Request a Call Back</h3>
<h4><label for="name">Name</label></h4>
<input id="name" name="name" type="text" />
<h4><label for="email">Email</label></h4>
<input id="email" name="email" type="text" />
<h4><label for="phone">Phone</label></h4>
<input id="phone" name="phone" type="text" />
<input id="submit" type="submit" value="Submit" />
<input type="hidden" name="submitted" id="submitted" value="true" />
<input type="hidden" name="required" id="required" class="required" />
</form>
<?php
/*
* Template Name: Contact
*/
if( isset( $_POST['submitted'] ) ) {
$to = get_option( 'admin_email' );
if( trim( $_POST['name'] ) === '' ) {
$nameError = 'You did not enter your name.';
$hasError = true;
} else {
$name = trim( $_POST['name'] );
}
if( trim( $_POST['email'] ) === '' ) {
$emailError = 'You did not enter your email address.';
$hasError = true;
} else if( !preg_match( "/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim( $_POST['email'] ) ) ) {
$emailError = 'You entered an invalid email address.';
$hasError = true;
} else {
$email = trim( $_POST['email'] );
}
if( trim( $_POST['phone'] ) === '' ) {
$phoneError = 'You did not enter your telephone number.';
$hasError = true;
} else if( !is_numeric( $_POST['phone'] ) ) {
$phoneError = 'You have entered an invalid phone number.';
$hasError = true;
} else {
$phone = trim( $_POST['phone'] );
}
if( !empty( $_POST['required'] ) ) {
$requiredError = 'You appear to be a robot. If you are human, please try again.';
$hasError = true;
}
if( !isset( $hasError ) ) {
$subject = 'Call Back Request from ' . $name;
$body = "Name: $name \n\nEmail: $email \n\nPhone: $phone";
$headers = 'From: ' . $name . ' <' . $emailTo . '>' . "\r\n" . 'Reply-To: ' . $email;
wp_mail( $to, $subject, $body, $headers );
$emailSent = true;
}
}
?>
<?php get_header(); ?>
<div class="content" role="main">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php if( isset( $emailSent ) && $emailSent == true ) { ?>
<p><strong>Your message has been sent successfully. Someone will be in touch shortly. Thanks.</strong></p>
<?php the_content(); ?>
<?php } else { ?>
<?php if( isset( $hasError ) ) { ?>
<p class="error">Sorry, an error has occured.<p>
<ul>
<?php if( $nameError != '' ) { ?>
<li>
<span class="error"><?php echo $nameError; ?></span>
</li>
<?php } ?>
<?php if( $emailError != '' ) { ?>
<li>
<span class="error"><?php echo $emailError; ?></span>
</li>
<?php } ?>
<?php if( $phoneError != '' ) { ?>
<li>
<span class="error"><?php echo $phoneError; ?></span>
</li>
<?php } ?>
<?php if( !empty( $requiredError ) ) { ?>
<li>
<span class="error"><?php echo $requiredError; ?></span>
</li>
<?php } ?>
</ul>
<?php } ?>
<?php the_content(); ?>
<?php } ?>
</div>
</div>
<?php endwhile; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<form name="quick-contact" class="quick-contact" method="post" action="<?php bloginfo( 'url' ); ?>/get-in-touch/">
<h3>Request a Call Back</h3>
<h4><label for="full-name">Full Name</label></h4>
<input id="full-name" name="full-name" type="text" />
<h4><label for="email">Email</label></h4>
<input id="email" name="email" type="text" />
<h4><label for="phone">Phone</label></h4>
<input id="phone" name="phone" type="text" />
<input id="submit" type="submit" value="Submit" />
<input type="hidden" name="required" id="required" class="required" />
</form>
<?php
/*
* Template Name: Contact
*/
?>
<?php get_header(); ?>
<?php
if( $_SERVER['REQUEST_METHOD'] == "POST" ) {
$to = get_option( 'admin_email' );
if( trim( $_POST['full-name'] ) === '' ) {
$nameError = 'You did not enter your name.';
$hasError = true;
} else {
$fullName = trim( $_POST['full-name'] );
}
if( trim( $_POST['email'] ) === '' ) {
$emailError = 'You did not enter your email address.';
$hasError = true;
} else if( !preg_match( "/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim( $_POST['email'] ) ) ) {
$emailError = 'You entered an invalid email address.';
$hasError = true;
} else {
$email = trim( $_POST['email'] );
}
if( trim( $_POST['phone'] ) === '' ) {
$phoneError = 'You did not enter your telephone number.';
$hasError = true;
} else if( !is_numeric( $_POST['phone'] ) ) {
$phoneError = 'You have entered an invalid phone number.';
$hasError = true;
} else {
$phone = trim( $_POST['phone'] );
}
if( !empty( $_POST['required'] ) ) {
$requiredError = 'You appear to be a robot. If you are human, please try again.';
$hasError = true;
}
if( !isset( $hasError ) ) {
if ( !isset( $to ) || ( $to == '' ) ) {
$to = get_option( 'admin_email' );
}
$subject = 'Call Back Request from ' . $fullName;
$body = "Name: $fullName <br />Email: $email <br />Phone: $phone";
$headers[] = 'From: ' . $fullName . ' <' . $email . '>';
$headers[] = 'Reply-To: ' . $email;
$headers[] = 'Content-type: text/html; charset=utf-8';
wp_mail( $to, $subject, $body, $headers );
$emailSent = true;
}
}
?>
<div class="content" role="main">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php if( isset( $emailSent ) && $emailSent == true ) { ?>
<p><strong>Your message has been sent successfully. Someone will be in touch shortly. Thanks.</strong></p>
<?php } else { ?>
<?php var_dump($headers); ?>
<?php if( isset( $hasError ) ) { ?>
<p class="error">Sorry, an error has occured.<p>
<ul>
<?php if( $nameError != '' ) { ?>
<li>
<span class="error"><?php echo $nameError; ?></span>
</li>
<?php } ?>
<?php if( $emailError != '' ) { ?>
<li>
<span class="error"><?php echo $emailError; ?></span>
</li>
<?php } ?>
<?php if( $phoneError != '' ) { ?>
<li>
<span class="error"><?php echo $phoneError; ?></span>
</li>
<?php } ?>
<?php if( !empty( $requiredError ) ) { ?>
<li>
<span class="error"><?php echo $requiredError; ?></span>
</li>
<?php } ?>
</ul>
<?php } ?>
<?php } ?>
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
告诉我是否收到电子邮件,如果没有更改
$to=get_选项('admin_email');
具有
$to=your@email.com; //例
当你改变了,试着告诉我它是否有效;) 告诉我是否收到电子邮件,如果没有更改
$to=get_选项('admin_email');
具有
$to=your@email.com; //例
当你改变了,试着告诉我它是否有效;) 好了,伙计们
看来我终于解决了问题。所有的代码,所有的变体都很好,除了一件小事。WordPress系统使用变量“$name”来显示博客名称,当我在表单上使用它作为名称字段的变量时,它导致了问题。谁知道呢
无论如何,我只是简单地将它改为使用“$fullName”,并将表单上的id和name属性改为“fullName”,一切都很顺利
感谢@maiorano84为我指明了调试问题的正确方向
无论如何,下面是我修改过的代码,其他人可以使用它
表格代码
<form name="quick-contact" class="quick-contact" method="post" action="<?php bloginfo('url'); ?>/get-in-touch/">
<h3>Request a Call Back</h3>
<h4><label for="name">Name</label></h4>
<input id="name" name="name" type="text" />
<h4><label for="email">Email</label></h4>
<input id="email" name="email" type="text" />
<h4><label for="phone">Phone</label></h4>
<input id="phone" name="phone" type="text" />
<input id="submit" type="submit" value="Submit" />
<input type="hidden" name="submitted" id="submitted" value="true" />
<input type="hidden" name="required" id="required" class="required" />
</form>
<?php
/*
* Template Name: Contact
*/
if( isset( $_POST['submitted'] ) ) {
$to = get_option( 'admin_email' );
if( trim( $_POST['name'] ) === '' ) {
$nameError = 'You did not enter your name.';
$hasError = true;
} else {
$name = trim( $_POST['name'] );
}
if( trim( $_POST['email'] ) === '' ) {
$emailError = 'You did not enter your email address.';
$hasError = true;
} else if( !preg_match( "/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim( $_POST['email'] ) ) ) {
$emailError = 'You entered an invalid email address.';
$hasError = true;
} else {
$email = trim( $_POST['email'] );
}
if( trim( $_POST['phone'] ) === '' ) {
$phoneError = 'You did not enter your telephone number.';
$hasError = true;
} else if( !is_numeric( $_POST['phone'] ) ) {
$phoneError = 'You have entered an invalid phone number.';
$hasError = true;
} else {
$phone = trim( $_POST['phone'] );
}
if( !empty( $_POST['required'] ) ) {
$requiredError = 'You appear to be a robot. If you are human, please try again.';
$hasError = true;
}
if( !isset( $hasError ) ) {
$subject = 'Call Back Request from ' . $name;
$body = "Name: $name \n\nEmail: $email \n\nPhone: $phone";
$headers = 'From: ' . $name . ' <' . $emailTo . '>' . "\r\n" . 'Reply-To: ' . $email;
wp_mail( $to, $subject, $body, $headers );
$emailSent = true;
}
}
?>
<?php get_header(); ?>
<div class="content" role="main">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php if( isset( $emailSent ) && $emailSent == true ) { ?>
<p><strong>Your message has been sent successfully. Someone will be in touch shortly. Thanks.</strong></p>
<?php the_content(); ?>
<?php } else { ?>
<?php if( isset( $hasError ) ) { ?>
<p class="error">Sorry, an error has occured.<p>
<ul>
<?php if( $nameError != '' ) { ?>
<li>
<span class="error"><?php echo $nameError; ?></span>
</li>
<?php } ?>
<?php if( $emailError != '' ) { ?>
<li>
<span class="error"><?php echo $emailError; ?></span>
</li>
<?php } ?>
<?php if( $phoneError != '' ) { ?>
<li>
<span class="error"><?php echo $phoneError; ?></span>
</li>
<?php } ?>
<?php if( !empty( $requiredError ) ) { ?>
<li>
<span class="error"><?php echo $requiredError; ?></span>
</li>
<?php } ?>
</ul>
<?php } ?>
<?php the_content(); ?>
<?php } ?>
</div>
</div>
<?php endwhile; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<form name="quick-contact" class="quick-contact" method="post" action="<?php bloginfo( 'url' ); ?>/get-in-touch/">
<h3>Request a Call Back</h3>
<h4><label for="full-name">Full Name</label></h4>
<input id="full-name" name="full-name" type="text" />
<h4><label for="email">Email</label></h4>
<input id="email" name="email" type="text" />
<h4><label for="phone">Phone</label></h4>
<input id="phone" name="phone" type="text" />
<input id="submit" type="submit" value="Submit" />
<input type="hidden" name="required" id="required" class="required" />
</form>
<?php
/*
* Template Name: Contact
*/
?>
<?php get_header(); ?>
<?php
if( $_SERVER['REQUEST_METHOD'] == "POST" ) {
$to = get_option( 'admin_email' );
if( trim( $_POST['full-name'] ) === '' ) {
$nameError = 'You did not enter your name.';
$hasError = true;
} else {
$fullName = trim( $_POST['full-name'] );
}
if( trim( $_POST['email'] ) === '' ) {
$emailError = 'You did not enter your email address.';
$hasError = true;
} else if( !preg_match( "/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim( $_POST['email'] ) ) ) {
$emailError = 'You entered an invalid email address.';
$hasError = true;
} else {
$email = trim( $_POST['email'] );
}
if( trim( $_POST['phone'] ) === '' ) {
$phoneError = 'You did not enter your telephone number.';
$hasError = true;
} else if( !is_numeric( $_POST['phone'] ) ) {
$phoneError = 'You have entered an invalid phone number.';
$hasError = true;
} else {
$phone = trim( $_POST['phone'] );
}
if( !empty( $_POST['required'] ) ) {
$requiredError = 'You appear to be a robot. If you are human, please try again.';
$hasError = true;
}
if( !isset( $hasError ) ) {
if ( !isset( $to ) || ( $to == '' ) ) {
$to = get_option( 'admin_email' );
}
$subject = 'Call Back Request from ' . $fullName;
$body = "Name: $fullName <br />Email: $email <br />Phone: $phone";
$headers[] = 'From: ' . $fullName . ' <' . $email . '>';
$headers[] = 'Reply-To: ' . $email;
$headers[] = 'Content-type: text/html; charset=utf-8';
wp_mail( $to, $subject, $body, $headers );
$emailSent = true;
}
}
?>
<div class="content" role="main">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php if( isset( $emailSent ) && $emailSent == true ) { ?>
<p><strong>Your message has been sent successfully. Someone will be in touch shortly. Thanks.</strong></p>
<?php } else { ?>
<?php var_dump($headers); ?>
<?php if( isset( $hasError ) ) { ?>
<p class="error">Sorry, an error has occured.<p>
<ul>
<?php if( $nameError != '' ) { ?>
<li>
<span class="error"><?php echo $nameError; ?></span>
</li>
<?php } ?>
<?php if( $emailError != '' ) { ?>
<li>
<span class="error"><?php echo $emailError; ?></span>
</li>
<?php } ?>
<?php if( $phoneError != '' ) { ?>
<li>
<span class="error"><?php echo $phoneError; ?></span>
</li>
<?php } ?>
<?php if( !empty( $requiredError ) ) { ?>
<li>
<span class="error"><?php echo $requiredError; ?></span>
</li>
<?php } ?>
</ul>
<?php } ?>
<?php } ?>
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
好的,伙计们
看来我终于解决了问题。所有的代码,所有的变体都很好,除了一件小事。WordPress系统使用变量“$name”来显示博客名称,当我在表单上使用它作为名称字段的变量时,它导致了问题。谁知道呢
无论如何,我只是简单地将它改为使用“$fullName”,并将表单上的id和name属性改为“fullName”,一切都很顺利
感谢@maiorano84为我指明了调试问题的正确方向
无论如何,下面是我修改过的代码,其他人可以使用它
表格代码
<form name="quick-contact" class="quick-contact" method="post" action="<?php bloginfo('url'); ?>/get-in-touch/">
<h3>Request a Call Back</h3>
<h4><label for="name">Name</label></h4>
<input id="name" name="name" type="text" />
<h4><label for="email">Email</label></h4>
<input id="email" name="email" type="text" />
<h4><label for="phone">Phone</label></h4>
<input id="phone" name="phone" type="text" />
<input id="submit" type="submit" value="Submit" />
<input type="hidden" name="submitted" id="submitted" value="true" />
<input type="hidden" name="required" id="required" class="required" />
</form>
<?php
/*
* Template Name: Contact
*/
if( isset( $_POST['submitted'] ) ) {
$to = get_option( 'admin_email' );
if( trim( $_POST['name'] ) === '' ) {
$nameError = 'You did not enter your name.';
$hasError = true;
} else {
$name = trim( $_POST['name'] );
}
if( trim( $_POST['email'] ) === '' ) {
$emailError = 'You did not enter your email address.';
$hasError = true;
} else if( !preg_match( "/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim( $_POST['email'] ) ) ) {
$emailError = 'You entered an invalid email address.';
$hasError = true;
} else {
$email = trim( $_POST['email'] );
}
if( trim( $_POST['phone'] ) === '' ) {
$phoneError = 'You did not enter your telephone number.';
$hasError = true;
} else if( !is_numeric( $_POST['phone'] ) ) {
$phoneError = 'You have entered an invalid phone number.';
$hasError = true;
} else {
$phone = trim( $_POST['phone'] );
}
if( !empty( $_POST['required'] ) ) {
$requiredError = 'You appear to be a robot. If you are human, please try again.';
$hasError = true;
}
if( !isset( $hasError ) ) {
$subject = 'Call Back Request from ' . $name;
$body = "Name: $name \n\nEmail: $email \n\nPhone: $phone";
$headers = 'From: ' . $name . ' <' . $emailTo . '>' . "\r\n" . 'Reply-To: ' . $email;
wp_mail( $to, $subject, $body, $headers );
$emailSent = true;
}
}
?>
<?php get_header(); ?>
<div class="content" role="main">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php if( isset( $emailSent ) && $emailSent == true ) { ?>
<p><strong>Your message has been sent successfully. Someone will be in touch shortly. Thanks.</strong></p>
<?php the_content(); ?>
<?php } else { ?>
<?php if( isset( $hasError ) ) { ?>
<p class="error">Sorry, an error has occured.<p>
<ul>
<?php if( $nameError != '' ) { ?>
<li>
<span class="error"><?php echo $nameError; ?></span>
</li>
<?php } ?>
<?php if( $emailError != '' ) { ?>
<li>
<span class="error"><?php echo $emailError; ?></span>
</li>
<?php } ?>
<?php if( $phoneError != '' ) { ?>
<li>
<span class="error"><?php echo $phoneError; ?></span>
</li>
<?php } ?>
<?php if( !empty( $requiredError ) ) { ?>
<li>
<span class="error"><?php echo $requiredError; ?></span>
</li>
<?php } ?>
</ul>
<?php } ?>
<?php the_content(); ?>
<?php } ?>
</div>
</div>
<?php endwhile; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<form name="quick-contact" class="quick-contact" method="post" action="<?php bloginfo( 'url' ); ?>/get-in-touch/">
<h3>Request a Call Back</h3>
<h4><label for="full-name">Full Name</label></h4>
<input id="full-name" name="full-name" type="text" />
<h4><label for="email">Email</label></h4>
<input id="email" name="email" type="text" />
<h4><label for="phone">Phone</label></h4>
<input id="phone" name="phone" type="text" />
<input id="submit" type="submit" value="Submit" />
<input type="hidden" name="required" id="required" class="required" />
</form>
<?php
/*
* Template Name: Contact
*/
?>
<?php get_header(); ?>
<?php
if( $_SERVER['REQUEST_METHOD'] == "POST" ) {
$to = get_option( 'admin_email' );
if( trim( $_POST['full-name'] ) === '' ) {
$nameError = 'You did not enter your name.';
$hasError = true;
} else {
$fullName = trim( $_POST['full-name'] );
}
if( trim( $_POST['email'] ) === '' ) {
$emailError = 'You did not enter your email address.';
$hasError = true;
} else if( !preg_match( "/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim( $_POST['email'] ) ) ) {
$emailError = 'You entered an invalid email address.';
$hasError = true;
} else {
$email = trim( $_POST['email'] );
}
if( trim( $_POST['phone'] ) === '' ) {
$phoneError = 'You did not enter your telephone number.';
$hasError = true;
} else if( !is_numeric( $_POST['phone'] ) ) {
$phoneError = 'You have entered an invalid phone number.';
$hasError = true;
} else {
$phone = trim( $_POST['phone'] );
}
if( !empty( $_POST['required'] ) ) {
$requiredError = 'You appear to be a robot. If you are human, please try again.';
$hasError = true;
}
if( !isset( $hasError ) ) {
if ( !isset( $to ) || ( $to == '' ) ) {
$to = get_option( 'admin_email' );
}
$subject = 'Call Back Request from ' . $fullName;
$body = "Name: $fullName <br />Email: $email <br />Phone: $phone";
$headers[] = 'From: ' . $fullName . ' <' . $email . '>';
$headers[] = 'Reply-To: ' . $email;
$headers[] = 'Content-type: text/html; charset=utf-8';
wp_mail( $to, $subject, $body, $headers );
$emailSent = true;
}
}
?>
<div class="content" role="main">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php if( isset( $emailSent ) && $emailSent == true ) { ?>
<p><strong>Your message has been sent successfully. Someone will be in touch shortly. Thanks.</strong></p>
<?php } else { ?>
<?php var_dump($headers); ?>
<?php if( isset( $hasError ) ) { ?>
<p class="error">Sorry, an error has occured.<p>
<ul>
<?php if( $nameError != '' ) { ?>
<li>
<span class="error"><?php echo $nameError; ?></span>
</li>
<?php } ?>
<?php if( $emailError != '' ) { ?>
<li>
<span class="error"><?php echo $emailError; ?></span>
</li>
<?php } ?>
<?php if( $phoneError != '' ) { ?>
<li>
<span class="error"><?php echo $phoneError; ?></span>
</li>
<?php } ?>
<?php if( !empty( $requiredError ) ) { ?>
<li>
<span class="error"><?php echo $requiredError; ?></span>
</li>
<?php } ?>
</ul>
<?php } ?>
<?php } ?>
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Dumb问题:您的进入触摸页面是否使用定义的联系人模板?是的,它使用的是正确的Contact.php模板。我注意到,当您直接导航到进入触摸页面(无需提交表单)时,页面内容呈现没有问题。但是,在提交表单时,找不到任何内容。如果注释掉if(isset($\u POST['submitted'])
块之间的所有内容,会发生什么?提交表单时内容是否呈现?如果在该块中放置echo语句,echo语句是否会激发?请尝试将内容类型和编码添加到标题中,以查看其是否有效-$headers.='内容类型:text/html;字符集=utf-8\r\n'@谢谢。不,echo语句没有输出任何内容。愚蠢的问题:您的进入触摸页面是否使用定义的联系人模板?是的,它使用的是正确的Contact.php模板。我注意到,当您直接导航到进入触摸页面(无需提交表单)时,页面内容呈现没有问题。但是,在提交表单时,找不到任何内容。如果注释掉if(isset($\u POST['submitted'])
块之间的所有内容,会发生什么?提交表单时内容是否呈现?如果在该块中放置echo语句,echo语句是否会激发?请尝试将内容类型和编码添加到标题中,以查看其是否有效-$headers.='内容类型:text/html;字符集=utf-8\r\n'@谢谢。不,echo语句不输出任何内容。这不会影响任何内容,因为我已经测试了$to变量,它将管理员电子邮件作为字符串包含,因此它已设置并工作。此外,电子邮件未到达。正如我所说的,表单不起作用。我只是尝试了代码,所以工作正常,而不是这样:if(!isset($to)| |($to=''){$to=get_选项('admin_email');}只使用:$to='yourmail'//如果代码仍然不起作用,就不要使用它,即使有了更改。我已经修改了上面的问题,以显示完整的contact.php代码。您是否尝试将完整的代码放在一个唯一的文件中?我尝试过这样做,它工作了,这不会影响任何事情,因为我已经测试了$to变量,它以字符串形式包含管理员电子邮件,因此它已设置并工作。此外,电子邮件未送达。正如我所说的,表单不起作用。我只是尝试了代码,所以工作正常,而不是这样:if(!isset($to)| |($to=''){$to=get_选项('admin_email');}只使用:$to='yourmail'//如果代码仍然不起作用,就不要使用它,即使有了更改。我已经修改了上面的问题,以显示完整的contact.php代码。您是否尝试将完整的代码放在一个唯一的文件中?我尝试了,结果成功了!困难的一个,做得很好,为得到它的底部,并感谢张贴解决方案。记住把你自己的答案标记为正确,这样就表明问题已经解决了。哎哟!困难的一个,做得很好,为得到它的底部,并感谢张贴解决方案。记住把你自己的答案标记为正确,这样就表明它已经解决了。