【问题标题】:How to get POST to submit email如何让 POST 提交电子邮件
【发布时间】:2015-10-27 09:57:05
【问题描述】:

抱歉,如果这真的很容易,我应该知道这一点。 因此,我通过我网站上的联系表格向电子邮件地址发送了很多垃圾邮件,所以我决定将验证码添加到网站,我已经设法让验证码发挥作用,因为它会发出消息说你单击发送时必须勾选验证框等(不勾选框),但当您勾选框时,您会收到一条成功的消息,但电子邮件没有发送。

我将在下面发布代码 -

联系页面上的php -

    <?php 
    if(isset($_POST['submit'])){
    $to = "MYEMAIL@EMAIL.COM"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['first_name'];
    $subject = "MY Service call form";
    $subject2 = "Copy of MY Service call form";
    $telephone_number = $_POST['telephone_number'];
    $address = $_POST['address'];
    $element2 = $_POST['element2'];
    $contract = $_POST['contract'];
    $message = $_POST['message'];
    $playerinfo = "\n Name : " . $first_name . "\n address : " . $address .     "\n telephone_number : " . $telephone_number . "\n choice : " . $element2 . "\n     contract : " . $contract . "\n message : " . $message . " " .     $_POST['playerinfo'];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" .     $_POST['message'];
    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$playerinfo,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the     message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you     shortly.";
    }?>

这里是html表单

    <form action="form.php" method="post">
       <input type="text" name="first_name" style="border:2px solid #0072ff;" required><br>
      <input type="email" name="email" style="border:2px solid #0072ff;" required><br>
      <input type="text" name="telephone_number" style="border:2px solid #0072ff;"><br/>
      <input type="text" name="address" style="border:2px solid #0072ff;" required><br>
        <label class="emf-label-desc" for="element2">Service call category</label>


              <input id="element_2_0" name="element2" value="UPVC Frames" class="validate[optional]" type="radio" /><label class="padleft-w5" for="element_2_0">UPVC Frames</label>


              <input id="element_2_1" name="element2" value="Glass" class="validate[optional]" type="radio" /><label class="padleft-w5" for="element_2_1">Glass</label>


              <input id="element_2_2" name="element2" value="Composite Doors" class="validate[optional]" type="radio" /><label class="padleft-w5" for="element_2_2">Composite Doors</label>


              <input id="element_2_3" name="element2" value="UPVC Doors" class="validate[optional]" type="radio" /><label class="padleft-w5" for="element_2_3">UPVC Doors</label>


              <input id="element_2_4" name="element2" value="Conservatory" class="validate[optional]" type="radio" /><label class="padleft-w5" for="element_2_4">Conservatory</label>


              <input id="element_2_5" name="element2" value="Plastics" class="validate[optional]" type="radio" /><label class="padleft-w5" for="element_2_5">Plastics</label>


              <input id="element_2_6" name="element2" value="Other" class="validate[optional]" type="radio" /><label class="padleft-w5" for="element_2_6">Other</label>
               Do you have a Contract Number? if so please enter: <input type="text" name="contract" style="border:2px solid #0072ff;" required><br>
         <div class="g-recaptcha" data-sitekey="HIDINGMYSECRETKEY"></div>

 <br><textarea rows="10" name="message" cols="50" style="border:2px solid #0072ff;" required></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>

这是我的 form.php 来确认验证码

    <?php
    if(isset($_POST['g-recaptcha-response'])){
          $captcha=$_POST['g-recaptcha-response'];
        }
        if(!$captcha){
          echo '<h2>Please check the the captcha form, go back and tick the box       to confirm you are not a spammer. <a href="http://www.mgwindows.com/repairs.php">CLICK HERE TO GO BACK</a></h2>';
          exit;
        }
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=HIDINGMYSECRETKEY&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
        if($response.success==false)
        {
          echo '<h2>You are spammer !</h2>';
        }else
        {
          echo '<h2>Thanks for posting comment.</h2>';
        }
?>

再次感谢您对此提供的任何帮助,问题再次是您完成验证码后,电子邮件不会发送到我的服务电子邮件帐户。

【问题讨论】:

  • 抱歉,我不确定如何在此处正确发布代码。
  • 您的 PHP 服务器上的电子邮件服务器是否正常工作?

标签: php html forms


【解决方案1】:

只需用这个替换你的 php 代码..

<?php 
    if(isset($_POST['submit'])){

        if(isset($_POST['g-recaptcha-response'])){
            $captcha=$_POST['g-recaptcha-response'];
        }
        if(!$captcha){
        echo '<h2>Please check the the captcha form, go back and tick the box       to confirm you are not a spammer. <a href="http://www.mgwindows.com/repairs.php">CLICK HERE TO GO BACK</a></h2>';
          exit;
        }
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6Lfsqw8TAAAAAEeldyYfwEhQQuhOXbjBBG0dzPwl&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
        if($response.success==false)
        {
          echo '<h2>You are spammer !</h2>';
          exit;
        }else
        {
          echo '<h2>Thanks for posting comment.</h2>';

            $to = "MYEMAIL@EMAIL.COM"; // this is your Email address
            $from = $_POST['email']; // this is the sender's Email address
            $first_name = $_POST['first_name'];
            $subject = "MY Service call form";
            $subject2 = "Copy of MY Service call form";
            $telephone_number = $_POST['telephone_number'];
            $address = $_POST['address'];
            $element2 = $_POST['element2'];
            $contract = $_POST['contract'];
            $message = $_POST['message'];
            $playerinfo = "\n Name : " . $first_name . "\n address : " . $address .     "\n telephone_number : " . $telephone_number . "\n choice : " . $element2 . "\n     contract : " . $contract . "\n message : " . $message . " " .     $_POST['playerinfo'];
            $message2 = "Here is a copy of your message " . $first_name . "\n\n" .     $_POST['message'];
            $headers = "From:" . $from;
            $headers2 = "From:" . $to;
            mail($to,$subject,$playerinfo,$headers);
            mail($from,$subject2,$message2,$headers2); // sends a copy of the     message to the sender
            echo "Mail Sent. Thank you " . $first_name . ", we will contact you     shortly.";
        }

    }
?>

【讨论】:

  • 完美,非常感谢,这很有效,非常感谢,并感谢您提出解决我问题的建议。
【解决方案2】:

你永远不会提交你的表单,因此你的帖子值没有得到任何地方,如果没有一些 ajax 或使用这个简单的 jquery 脚本,你就无法做到这一点:

<script type='text/javascript'>

 $(document).ready(function() { 
  $('input[name=name]').change(function(){
    $('form').submit();
 });
});

</script>

【讨论】:

    【解决方案3】:

    我不太确定我是否遇到了您的问题,但如果您在成功验证码后从未发送过电子邮件,您应该尝试将您发布的第一块代码添加到您的验证码中:

     if(isset($_POST['g-recaptcha-response'])){
          $captcha=$_POST['g-recaptcha-response'];
        }
        if(!$captcha){
          echo '<h2>Please check the the captcha form, go back and tick the box       to confirm you are not a spammer. <a href="http://www.mgwindows.com/repairs.php">CLICK HERE TO GO BACK</a></h2>';
          exit;
        }
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=HIDINGMYSECRETKEY&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
        if($response.success==false)
        {
          echo '<h2>You are spammer !</h2>';
        }else
        {
          // add your mail sending code here <------------------
          echo '<h2>Thanks for posting comment.</h2>
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多