douyu7618 2019-03-11 06:40
浏览 22

我正在更换时,我的电子邮件代码无效

When i am replacing the email with my email id, it shows "?ok" and if i am leaving it default it shows "Your emails was Sent Successfully"

i guess there is something wrong with php code, when i edit it shows "?ok", and when i reset it back it agains shows "?ok" until i don't upload the original file which i edited (it has same code, just not opened or edited)

Here is my Php code:

 <?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 . "
";
    $headers .= "Reply-To: ". $email . "
";
    $headers .= "MIME-Version: 1.0
";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1
";   

    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 /> 
" : null;
        $response .= (isset($error['email'])) ? $error['email'] . "<br /> 
" : null;
        $response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;            
        echo $response;    
    } # end if - there was a validation error    
}

?>

HTML CODE:

            <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 -->

Please suggest what are the changes i need to do to make work. you can check here how error shows https://freesoft64.com/test.html

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程