【问题标题】:What language(s) i have to use to make a success or an error situation for PHP mail form?我必须使用什么语言来使 PHP 邮件表单成功或出错?
【发布时间】:2015-07-21 22:10:05
【问题描述】:

我有一个已经编码的 PHP 邮件表单:

如果表单成功发送邮件,我想显示一个我使用 CSS 和 jQuery 编码的横幅:

我想知道我可以使用什么语言来实现它?你有什么建议?

这是我的表单 html 代码:

<form id="my_form" enctype="multipart/form-data" method=POST action=formmail.php>
    <input type="hidden" name="subject" value="formmail">


<!-- PSEUDO -->

<p>

    <h3>
        PSEUDO
        <font class="color-red">
        * :
        </font>
        <span class="padding1"><input type="text" class="form-control" name="pseudo" aria-required="true" aria-invalid="false"></span></p><br>


<!-- EMAIL -->

    <p> 
         EMAIL
         <font class="color-red">
             * :
         </font>
         <span class="your-email padding1"><input type="email" class="form-control" name="email" aria-required="true" aria-invalid="false"></span></p><br>

   <!-- MOTO -->

    <p>
        QUOTE
        <font class="color-red">
        * :
        </font>

    <span class="moto padding1"><input type="moto" class="form-control" name="moto" aria-invalid="false"></span> </p><br>



  <!-- LINK OF THE GIF -->  

<p>
    LINK OF THE GIF
    <font class="color-red">
    * :
    </font>
     <span class="link-url padding1"><input type="link_url" class="form-control" name="link_url" aria-invalid="false"></span> </p><br>


  <!-- RECAPTCHA -->  
    <div align="center">
    <p><div class="g-recaptcha" data-sitekey="6LehFQoTAAAAAMHlOs6vgktrCdFo485AoHwmp9Cp"></div></p><br><h3>


    <!-- SUBMIT -->

<p><input type="image" src="img/submitbutton.png" value="send"/><img class="ajax-loader" src="http://s584101063.onlinehome.fr/wp-content/plugins/contact-form-7/images/ajax-loader.gif" alt="Envoi en cours ..." style="visibility: hidden;"></p></div>


</div>
</form>

这是我的 PHP:

if($_SERVER["REQUEST_METHOD"] === "POST")
    {
        //form submitted

        //check if other form details are correct

        //verify captcha
        $recaptcha_secret = "MY_SECRET_RECAPTCHA";
        $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']);
        $response = json_decode($response, true);
        if($response["success"] === true)
        {

            Header("Location: MY_WEBSITE");





            $TO = "MY_MAIL";

$subject = "Submission";

$h = "From: " . $_POST['email'];
 $pseudo = $_POST['pseudo'];
 $email = $_POST['email'];
 $link_url = $_POST['link_url'];
 $moto = $_POST['moto'];

$HTTP_POST_VARS = $_POST;


$message = "Pseudo : " . $pseudo . "\n\n " . "Email : " . $email . " \n\n" . "Text : " . $moto . "\n\n " . "URL du GIF : " . $link_url;

mail($TO, $subject, $message, $h);








        }



        else
        {
            $result
        }
    }


?>

【问题讨论】:

  • 您的脚本对希望滥用您的代码以向伟哥和加拿大药店发送电子邮件的垃圾邮件发送者开放。您应该考虑清理用户输入。
  • 不知道你在问什么
  • @skrilled 验证码会有所帮助
  • @skrilled : 谢谢你的建议,我开始了
  • @Dagon 我想做一个活动(如果邮件发送与否),如果发送了,我的横幅就会出现,但我开始了,我不知道怎么做它发生了

标签: php jquery html forms email


【解决方案1】:

非常基本的想法:

$test=mail($TO, $subject, $message, $h);

if($test){
echo 'EmAIL WORK';
}else{
echo 'EmAIL Fail';

}

【讨论】:

    【解决方案2】:

    编辑:大衮的回答效果很好,但我的问题并不清楚,这是我发现做我想做的事:

    感谢 Dagon,但这并不是我真正期望做的, 我找到了方法,它有效:)

    <?php  
    if(isset($_GET['id']) AND $_GET['id']==2) {  
    
      echo '<script type="text/javascript">'; 
    
        echo ' 
        $("#success-bar").css("display", "inline");
        $("#success-bar").addClass("animated bounceInDown")
    
        $("#success-bar").one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", 
    
        function(){
    
            $("#success-bar").removeClass("animated bounceInDown")
    
            $( "#close2" ).click(function() {
    
            $("#success-bar").addClass("animated bounceInUp")
            $("#success-bar").hide()
    
    
            $("#success-bar").one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", 
    
        function(){
    
    $("#success-bar").addClass("animated bounceInDown")
    
            });
    
            });
    
            });';
    
    echo '</script>';   
    
    
    } 
    
    elseif(isset($_GET['id']) AND $_GET['id']==3) {
    
        echo 'FALSE';
    
    }
    
    ?> 
    

    【讨论】:

    • 好的,但您假设邮件是在未经检查的情况下发送的。由于您的 for 正在使用 POST,我看不到您检查的 get 变量是从哪里来的
    • 它由重定向到 id 的 php 邮件中的标头位置检查 :)
    • 当然根据验证码是否可以(如果当前可以发送邮件)
    • 不,您尝试发送它,这与检查它是否实际发送不同。
    • 对不起,我刚开始,目前我的英语不太好,这就是为什么提出一个可能相关的问题很复杂......
    猜你喜欢
    • 1970-01-01
    • 2018-06-23
    • 1970-01-01
    • 2019-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    相关资源
    最近更新 更多