0

So I'm fairly new to wordpress and not well knowledgable on how things work, so please a detailed answer on what I should be doing would be great!

So basically I created a form that takes in input from user does some calculations and then when they press submit that input is sent to me in an email.

It works just fine on a site that isn't ran by wordpress but on my other site it just wont send, I know the php code is running but the mailing isn't, would really love some help. Just to add this code is placed in the page section I think they're referred to by Gotenberg.. could be wrong.

I was using <?php ?> of course, but the php could wasn't running so I had to install a plugin and use this [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]
Patrick Q
  • 6,373
  • 2
  • 25
  • 34
Jack
  • 1
  • 1
  • "I know the php code is running" How do you know this? What debugging have you done? What _is_ happening? – Patrick Q Dec 17 '18 at 20:15
  • Hello there, what I meant is that the php in general is running, as in when I run an echo "hello"; it executes that wasn't happening when I was using but after using the plugin it executed. – Jack Dec 17 '18 at 20:19
  • Okay, so again, what _is_ happening? Do you get inside of the `if(isset($_POST['submit'])){` condition? Are `$from`, `$first_name`, and `$last_name` the values that you expect? Is your ""Mail Sent ..." message displayed? – Patrick Q Dec 17 '18 at 20:25
  • yeah it does, I think the mail() isn't running, the "mail sent...: message is being displayed but I'm not receiving an email, I googled around and apparently wordpress uses wp_mail() so I'm trying this out now. – Jack Dec 17 '18 at 20:33
  • Possible duplicate of [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – Patrick Q Dec 17 '18 at 20:36
  • I'll take a look at it! and if I figure it out I'll update here, thank you! – Jack Dec 17 '18 at 20:40

0 Answers0