更换时我的电子邮件代码不起作用

时间:2019-03-11 06:40:43

标签: php

当我用我的电子邮件ID替换电子邮件时,它显示“?ok”,如果我将其保留为默认值,则显示“您的电子邮件已成功发送”

我想PHP代码有问题,当我编辑它时显示“?ok”,当我重设它时,它再次显示“?ok”,直到我不上传我编辑过的原始文件(它具有相同的代码,只是没有打开或编辑)

这是我的PHP代码:

 <?php    
// Replace this with your own email address
$siteOwnersEmail = 'user@website.com';        
if($_POST) {    
    $name = trim(stripslashes($_POST['contactName']));
    $email = trim(stripslashes($_POST['contactEmail']));
    $subject = trim(stripslashes($_POST['contactSubject']));
    $contact_message = trim(stripslashes($_POST['contactMessage']));

    // Check Name
    if (strlen($name) < 2) {
        $error['name'] = "Please enter your name.";
    }
    // Check Email
    if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
        $error['email'] = "Please enter a valid email address.";
    }
    // Check Message
    if (strlen($contact_message) < 15) {
        $error['message'] = "Please enter your message. It should have at least 15 characters.";
    }
    // Subject
    if ($subject == '') { $subject = "Contact Form Submission"; }   

    // Set Message
    $message .= "Email from: " . $name . "<br />";
    $message .= "Email address: " . $email . "<br />";
    $message .= "Message: <br />";
    $message .= $contact_message;
    $message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";

    // Set From: header
    $from =  $name . " <" . $email . ">";

    // Email Headers
    $headers = "From: " . $from . "\r\n";
    $headers .= "Reply-To: ". $email . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";   

    if (!$error) {    
        ini_set("sendmail_from", $siteOwnersEmail); // for windows server
        $mail = mail($siteOwnersEmail, $subject, $message, $headers);

        if ($mail) { echo "OK"; }
        else { echo "Something went wrong. Please try again."; }

    } # end if - no validation error    
    else {    
        $response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
        $response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
        $response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;            
        echo $response;    
    } # end if - there was a validation error    
}

?>

HTML代码:

            <div class="contact-primary">

            <h3 class="h6">Send Us A Message</h3>

            <form name="contactForm" id="contactForm" method="post" action="" novalidate="novalidate">
                <fieldset>

                <div class="form-field">
                    <input name="contactName" type="text" id="contactName" placeholder="Your Name" value="" minlength="2" required="" aria-required="true" class="full-width">
                </div>
                <div class="form-field">
                    <input name="contactEmail" type="email" id="contactEmail" placeholder="Your Email" value="" required="" aria-required="true" class="full-width">
                </div>
                <div class="form-field">
                    <input name="contactSubject" type="text" id="contactSubject" placeholder="Subject" value="" class="full-width">
                </div>
                <div class="form-field">
                    <textarea name="contactMessage" id="contactMessage" placeholder="Write us a summary for your business and what we can do to help" rows="10" cols="50" required="" aria-required="true" class="full-width"></textarea>
                </div>
                <div class="form-field">
                    <button class="full-width btn--primary">Submit</button>
                    <div class="submit-loader">
                        <div class="text-loader">Sending...</div>
                        <div class="s-loader">
                            <div class="bounce1"></div>
                            <div class="bounce2"></div>
                            <div class="bounce3"></div>
                        </div>
                    </div>
                </div>

                </fieldset>
            </form>

            <!-- contact-warning -->
            <div class="message-warning">
                Something went wrong. Please try again.
            </div> 

            <!-- contact-success -->
            <div class="message-success">
                Your message was sent, thank you!<br>
            </div>

        </div> <!-- end contact-primary -->

请提出我需要做些什么更改才能工作。 您可以在此处检查错误如何显示https://freesoft64.com/test.html

0 个答案:

没有答案