我在WordPress中通过创建短代码使用下面的联系人代码。当我提交表单时,它会显示成功消息,但收件箱中没有收到任何电子邮件或垃圾邮件。谁能帮忙吗。
function contactform_func( $atts ) {
$atts = shortcode_atts( array(
\'to_email\' => \'\',
\'title\' => \'Contact enquiry - \'.get_bloginfo(\'url\'),
), $atts );
$cform = "<div class=\\"main-form-area\\" id=\\"contactform_main\\">";
$cerr = array();
if( isset($_POST[\'c_submit\']) && $_POST[\'c_submit\']==\'Submit\' ){
$name = trim( $_POST[\'c_name\'] );
$email = trim( $_POST[\'c_email\'] );
$phone = trim( $_POST[\'c_phone\'] );
$website = trim( $_POST[\'c_website\'] );
$comments = trim( $_POST[\'c_comments\'] );
$captcha = trim( $_POST[\'c_captcha\'] );
$captcha_cnf = trim( $_POST[\'c_captcha_confirm\'] );
if( !$name )
$cerr[\'name\'] = \'Please enter your name.\';
if( ! filter_var($email, FILTER_VALIDATE_EMAIL) )
$cerr[\'email\'] = \'Please enter a valid email.\';
if( !$phone )
$cerr[\'phone\'] = \'Please enter your phone number.\';
if( !$comments )
$cerr[\'comments\'] = \'Please enter your question / comments.\';
if( !$captcha || (md5($captcha) != $captcha_cnf) )
$cerr[\'captcha\'] = \'Please enter the correct answer.\';
if( count($cerr) == 0 ){
$subject = $atts[\'title\'];
$headers = "From: ".$name." <" . strip_tags($email) . ">\\r\\n";
$headers .= "MIME-Version: 1.0\\r\\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\\r\\n";
$message = \'<html><body>
<table>
<tr><td>Name: </td><td>\'.$name.\'</td></tr>
<tr><td>Email: </td><td>\'.$email.\'</td></tr>
<tr><td>Phone: </td><td>\'.$phone.\'</td></tr>
<tr><td>Website: </td><td>\'.$website.\'</td></tr>
<tr><td>Comments: </td><td>\'.$comments.\'</td></tr>
</table>
</body>
</html>\';
mail( $atts[\'to_email\'], $subject, $message, $headers);
$cform .= \'<div class="success_msg">Thank you! A representative will get back to you very shortly.</div>\';
unset( $name, $email, $phone, $website, $comments, $captcha );
}else{
$cform .= \'<div class="error_msg">\';
$cform .= implode(\'<br />\',$cerr);
$cform .= \'</div>\';
}
}
$capNum1 = rand(1,4);
$capNum2 = rand(1,5);
$capSum = $capNum1 + $capNum2;
$sumStr = $capNum1." + ".$capNum2 ." = ";
$cform .= "<form name=\\"contactform\\" action=\\"#contactform_main\\" method=\\"post\\">
<p class=\\"left\\"><input type=\\"text\\" name=\\"c_name\\" value=\\"". ( ( empty($name) == false ) ? $name : "" ) ."\\" placeholder=\\"Name\\" /></p>
<p class=\\"right\\"><input type=\\"email\\" name=\\"c_email\\" value=\\"". ( ( empty($email) == false ) ? $email : "" ) ."\\" placeholder=\\"Email\\" /></p><div class=\\"clear\\"></div>
<p class=\\"left\\"><input type=\\"tel\\" name=\\"c_phone\\" value=\\"". ( ( empty($phone) == false ) ? $phone : "" ) ."\\" placeholder=\\"Phone\\" /></p>
<p class=\\"right\\"><input type=\\"url\\" name=\\"c_website\\" value=\\"". ( ( empty($website) == false ) ? $website : "" ) ."\\" placeholder=\\"Website with prefix http://\\" /></p><div class=\\"clear\\"></div>
<p><textarea name=\\"c_comments\\" placeholder=\\"Message\\">". ( ( empty($comments) == false ) ? $comments : "" ) ."</textarea></p>";
$cform .= "<br /><p class=\\"left\\">$sumStr<input style=\\"width:200px;\\" type=\\"text\\" placeholder=\\"Captcha\\" value=\\"". ( ( empty($captcha) == false ) ? $captcha : "" ) ."\\" name=\\"c_captcha\\" /><input type=\\"hidden\\" name=\\"c_captcha_confirm\\" value=\\"". md5($capSum)."\\"></p><div class=\\"clear\\"></div>";
$cform .= "<p class=\\"sub\\"><input type=\\"submit\\" name=\\"c_submit\\" value=\\"Submit\\" /></p>
</form>
</div>";
return $cform;} add_shortcode( \'contactform\', \'contactform_func\' );