联系表单未提交点击提交'按键

时间:2015-09-01 14:01:17

标签: php html forms

我的联系表单在点击“发送消息”后没有提交,我似乎遇到了解决问题的问题。按钮,它不会响应或将我重定向到任何地方。

请注意,文件(HTML和PHP)位于实时服务器上。我需要帮助解决问题,在下面找到您的细读和建议的代码;

PHP

<?php
define("WEBMASTER_EMAIL", $_POST['sendto']);
if (WEBMASTER_EMAIL == 'hello@mycompany.com' || WEBMASTER_EMAIL == 'hello@mycompany.com') {
    die('<div class="alert alert-confirm"> <h6><strong>The recipient email is not correct</strong></h6></div>');    
} 
define("EMAIL_SUBJECT", $_POST['subject']);
if (EMAIL_SUBJECT == 'Enquiry from John Doe' || EMAIL_SUBJECT == 'Enquiry from John Doe website') {
    define("EMAIL_SUBJECT",'Contact');  
}
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$message = stripslashes($_POST['message']);
$custom = $_POST['fields'];
$custom = substr($custom, 0, -1);
$custom = explode(',', $custom);
$message_addition = '';
foreach ($custom as $c) {
    if ($c !== 'name' && $c !== 'email' && $c !== 'message' && $c !== 'subject') {
        $message_addition .= '<b>'.$c.'</b>: '.$_POST[$c].'<br />';
    }
}
if ($message_addition !== '') {
    $message = $message.'<br /><br />'.$message_addition;
}
$message = '<html><body>'.nl2br($message)."</body></html>";
$mail = mail(WEBMASTER_EMAIL, EMAIL_SUBJECT, $message,
     "From: ".$name." <".$email.">\r\n"
    ."Reply-To: ".$email."\r\n"
    ."X-Mailer: PHP/" . phpversion()
    ."MIME-Version: 1.0\r\n"
    ."Content-Type: text/html; charset=utf-8");
if($mail)
{
echo '
        <div class="alert alert-confirm">
            <strong>Confirm</strong>: Your message has been sent. Thank you!
        </div>
';
}
else
{
echo '
        <div class="alert alert-error">
            <strong>Psst...</strong>: Your message has not been sent, try again!
        </div>
';
}
?>

HTML

<form id="contact-form" class="checkform" action="#" target="contact-send.php" method="post" >

            <div class="form-row clearfix">
                <label for="name" class="req">Name *</label>
                <input type="text" name="name" class="name" id="name" value="" placeholder="name" />
            </div>

            <div class="form-row clearfix">
                <label for="email" class="req">Email *</label>
                <input type="text" name="email" class="email" id="email" value="" placeholder="email"/>
            </div>

            <div class="form-row clearfix textbox">
                <label for="message" class="req">Message *</label>
                <textarea name="message" class="message" id="message" rows="15" cols="50" placeholder="message"></textarea>
            </div>

            <div id="form-note">
                <div class="alert alert-error">
                    <strong>Error</strong>: Please check your entries!
                </div>
            </div>

            <div class="form-row form-submit">
                <input type="submit" name="submit_form" class="submit" value="Send Message" />
            </div>

            <input type="hidden" name="subject" value="Contact Subject Pond html" />
            <input type="hidden" name="fields" value="name,email,message," />
            <input type="hidden" name="sendto" value="hello@companyname.com" /> 

        </form>

感谢您预期的解决方案。

1 个答案:

答案 0 :(得分:1)

action属性必须是您的php文件,target属性可以是_blank_self_parent_top < / p>

<form id="contact-form" class="checkform" action="contact-send.php" method="post">