表单不工作/Jscript、PHP 或 HTML?

我在 html 中创建了一个站点,但电子邮件表单不起作用。不知道是Js的还是php的。我在 PHP 中尝试了 GET 方法而不是 POST 方法。我将电子邮件地址更改为现有地址。当我输入时<?php if(isset($_POST['contact_name']) != "contact_name"){,它会发送没有姓名、电子邮件地址、电话或消息的电子邮件。订阅者也一样

<?php

if(isset($_POST['contact_name']) != ""){

            $to = "abc@gmail.com";

            $from =  $_POST["contact_email"];

            $message = "&nbsp;&nbsp;&nbsp;&nbsp;<strong>Name: </strong>".$_POST["contact_name"]."<br />";

            $message .= "&nbsp;&nbsp;&nbsp;&nbsp;<strong>Email Address: </strong>".$_POST["contact_email"]."<br />";

            $message .= "&nbsp;&nbsp;&nbsp;&nbsp;<strong>Phone: </strong>".$_POST["contact_phone"]."<br />";

            $message .= "&nbsp;&nbsp;&nbsp;&nbsp; <strong>Message: </strong>".$_POST["message"]."<br />";

            $subject = 'Contact Enquiry';       

            $headers = "From: ".$_POST["contact_email"]."\n";

            $headers .= "MIME-Version: 1.0" . "\r\n";

            $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

            

            $send = mail($to,$subject,$message,$headers);

    

    

    

    if($send)

    {

        echo "success";

    }

    else

    {

        echo "error";

    }

}



if(isset($_POST['subscribe_name']) != ""){

            $to = "abc@gmail.com";

            $from =  $_POST["subscribe_email"];

            $message = "&nbsp;&nbsp;&nbsp;&nbsp;<strong>Name: </strong>".$_POST["subscribe_name"]."<br />";

            $message .= "&nbsp;&nbsp;&nbsp;&nbsp;<strong>Email Address: </strong>".$_POST["subscribe_email"]."<br />";

            $subject = 'Newsletter subscription';       

            $headers = "From: ".$_POST["subscribe_email"]."\n";

            $headers .= "MIME-Version: 1.0" . "\r\n";

            $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

            

            $send = mail($to,$subject,$message,$headers);

    

    

    

    if($send)

    {

        echo "success";

    }

    else

    {

        echo "error";

    }

}



?>


ITMISS
浏览 124回答 2
2回答

DIEA

解决了 !问题出在 .htaccess 中。我换了RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME}.html -fRewriteRule ^(.*)$&nbsp; $1.html [L]RewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME}.php -fRewriteRule ^(.*)$&nbsp; $1.php [L]RewriteCond %{REQUEST_URI} \.((html)|(php))$RewriteRule ^(.*)\.([^.]+)$&nbsp; $1 [R,L]和RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^([^\.]+)$ $1.html [NC,L]

BIG阳

在 validateContact 的 Javascript 中,您将布尔值与字符串进行比较。if(errors)其实应该是if(errors&nbsp;!=&nbsp;'')这是因为错误永远不会是真或假,它会有一个值或没有一个值。试一试,它应该可以解决您的问题
打开App,查看更多内容
随时随地看视频慕课网APP