在由Wordpress驱动的网站上,按下提交按钮后,PHP代码将不会发送电子邮件

时间:2018-12-17 20:02:33

标签: php wordpress

因此,我对Wordpress还是很陌生,对工作原理也不是很了解,所以请详细回答我应该做的事情!

所以基本上我创建了一个表单,该表单接受用户的输入并进行一些计算,然后当他们按“提交”时,该输入将通过电子邮件发送给我。

它在不是由wordpress运行的站点上工作正常,但是在我的其他站点上它就不会发送,我知道php代码正在运行,但是邮件却没有,真的希望获得一些帮助。 只是将这段代码添加到页面部分中,我认为它们是Gotenberg引用的。.可能是错误的。

我当然使用的是<?php ?>,但是php可能无法运行,因此我必须安装一个插件并使用此[insert_php] [/ insert_php]

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
  <script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->

<div class="container">
<div class="row">
  <div class="col-md-12">
 <!--   <small><i></i>Add alerts if form ok... success, else error.</i></small>
  <div class="alert alert-success"><strong><span class="glyphicon glyphicon-send"></span> Success! Message sent. (If form ok!)</strong></div>   
    <div class="alert alert-danger"><span class="glyphicon glyphicon-alert"></span><strong> Error! Please check the inputs. (If form error!)</strong></div>
  </div>-->
  <form role="form" action="" method="post" id="fr1">
    <div class="col-lg-6">
      <!--<div class="well well-sm"><strong><i class="glyphicon glyphicon-ok form-control-feedback"></i> Required Field</strong></div>-->
      <div class="form-group">
        <label for="InputName">Your Initial SR</label>
        <div class="input-group">
          <input type="text" class="form-control" name="value1" id="value1" placeholder="Enter initial SR" required>
          <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
      </div>
      <div class="form-group">
        <label for="InputName">Your Desired SR</label>
        <div class="input-group">
          <input type="text" class="form-control" name="value2" id="value2" placeholder="Enter desired SR" required>
          <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
      </div>








      <div class="form-group">
        <label for="InputEmail">Your Email</label>
        <div class="input-group">
          <input type="email" class="form-control" id="InputEmail" name="InputEmail" placeholder="Enter Email" required  >
          <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
      </div>
      <div class="form-group">
        <label for="InputMessage">Message</label>
        <div class="input-group">
          <textarea name="InputMessage" id="InputMessage" class="form-control" rows="5" required></textarea>
          <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
      </div>
       <div class="form-group">
             <!--<label class="control-label col-sm-2" for="diff">Difference</label>-->
             
                <input type="hidden" name="diff" id="diff" class="form-control" readonly />
              </div>

  <div class="form-group">
        <label for="InputName">Total Price</label>
        <div class="input-group">
           <input type="number" name="price" id="price" class="form-control" readonly />
      </div>



      <input type="submit" name="submit" id="submit" value="Submit" class="btn btn-info pull-right">
    </div></div>



  </form>
  
  </div>
</div>

</div>

[insert_php]
if(isset($_POST['submit'])){
    $to = "myemail@hotmail.com"; // this is your Email address
    $from = $_POST['InputEmail']; // this is the sender's Email address
    $first_name = $_POST['value1'];
    $last_name = $_POST['value2'];
    $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['InputEmail'];
    

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$message,$headers);
   
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    // You cannot use header and echo together. It's one or the other.
    }
[/insert_php]

0 个答案:

没有答案