-1

I need help with this php code... it doesn't redirect to the specified url

<?php

if(isset($_POST['submit'])){
$to = "email@domain.com"; // this is your Email address
$firstName = $_POST['$inf_tTzSYWEgQfQ4dJf9'];
$lastName = $_POST['lastName'];
$phoneNumber = $_POST['phoneNumber'];
$company = $_POST['company'];
$addressLine1 = $_POST['addressLine1'];
$addressLine2 = $_POST['addressLine2'];
$city = $_POST['city'];
$state = $_POST['state'];
$country = $_POST['country'];
$emailAddress = $_POST['emailAddress'];

$subject = "New Order - " . $firstName . " " . $lastName;
$body = "First Name: $firstName\n Last Name: $lastName\n Phone Number: $phoneNumber\n Company: $company\n Address Line 1: $addressLine1 \n Address Line 2: $addressLine2 \n City: $city\n State: $state\n Country: $country\n Email Address:$emailAddress";

header('Location: http://stackoverflow.com/');

}
?>

here's the HTML form

<form method="post" name="orderForm" id="orderForm" action="ordersubmithandler.php">

                    <div id="header">
                        <div class="CUSTOM_HTML">
                            <div id="customHeader">
                            </div>
                        </div>


                    <div id="IMAGE">
                        <div id="companyLogoTopBanner">
                            <img src="orderpage_files/jp126-666e1bad-894a-41bd-9d30-be234e2bf638-v2.png">
                        </div>
                    </div>
                            </div>


                    <div id="content">
                        <input id="previewMode" name="previewMode" type="hidden" value="false">

                        <div id="ORDER_FORM_PRODUCT_LIST">

                            <table class="viewCart tabular grid">

                                <tbody>
                                    <tr>
                                        <th class="leftAlign">Products</th>
                                        <th></th>
                                        <th class="rightAlign priceCell">Price</th>
                                        <th class="centerAlign qtyCell">Quantity</th>
                                        <th class="rightAlign priceCell">Total</th>
                                    </tr>

                                    <tr>
                                        <td colspan="2" class="productCell">
                                            <h1>Lorem ip</h1>
                                            <p class="productDescription">Lorem ipLorem ipLorem ipLorem ipLorem ipLorem ipLorem ipLorem ip</p>
                                            <span class="subscriptionPlan">One Time Payment of $80.00</span>
                                        </td>
                                        <td class="rightAlign priceCell">
                                            <span class="price">$80.00</span>
                                        </td>
                                        <td class="centerAlign qtyCell">1 </td>
                                        <td class="rightAlign priceCell">$80.00</td>
                                    </tr>

                                    <tr class="subtotal">
                                        <td class="leftAlign"><span class="totalPrice">Subtotal</span></td>
                                        <td co="" colspan="2"></td>
                                        <td class="qtyCell"></td>
                                        <td class="rightAlign priceCell"><span class="priceBold">$80.00</span></td>
                                    </tr>
                                </tbody>
                            </table>

                        </div>

                        <div id="CUSTOM_HTML">

                            <div id="productInformation">
                            <input name="" type="checkbox" checked="yes" value=""> <font color="black"><b>  I understand and agree I will be charged one payment today of $80.00 as FULL payment for the product. </b></font><b> <br> <br>
                            </b></div>

                        </div>

                        <b>

                            <div id="UP_SELLS">

                            </div>

                            <div id="ORDER_FORM_BILLING_ENTRY">

                                <link href="./orderpage_files/anti_spam.jsp" rel="stylesheet" type="text/css">
                                <script type="text/javascript">(function() {
                                var styleArray = ["/css/anti_spam.jsp"];
                                if (window.Infusion) {
                                    Infusion.stylesLoaded(styleArray);
                                } else if (window.InfusionStyles) {
                                    window.InfusionStyles.concat(styleArray);
                                } else {
                                    window.InfusionStyles = styleArray;
                                }

                                })();</script>
                                <div id="orderFormBillingEntry">
                                    <table class="billingTable tabular grid">

                                        <tbody>
                                            <tr>
                                                <th colspan="2" class="leftAlign">Billing Information</th>
                                            </tr>
                                            <tr>
                                                <td class="rightAlignTop"><label class="checkoutLabel">* First Name</label></td>
                                                <td>
                                                    <input class="regula-validation checkoutTop" data-constraints="@Required(label=&quot;First Name&quot;, groups=[customer])" id="firstName" name="firstName" size="10" type="text">
                                                    <input class="inf_a2f0ec38ba2014366540402764cde59e" id="inf_tTzSYWEgQfQ4dJf9" name="inf_tTzSYWEgQfQ4dJf9" type="text">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="rightAlign"><label class="checkoutLabel">* Last Name</label></td>
                                                <td><input class="regula-validation checkout" data-constraints="@Required(label=&quot;Last Name&quot;, groups=[customer])" id="lastName" name="lastName" size="12" type="text"></td>
                                            </tr>
                                            <tr>
                                                <td class="rightAlign"><label class="checkoutLabel">Company Name</label></td>
                                                <td><input class="checkout" id="company" name="company" size="25" type="text"></td>
                                            </tr>
                                            <tr>
                                                <td class="rightAlign"><label class="checkoutLabel">* Address - Line 1</label></td>
                                                <td><input class="regula-validation checkout" data-constraints="@Required(label=&quot;Address - Line 1&quot;, groups=[customer])" id="addressLine1" name="addressLine1" size="25" type="text"></td>
                                            </tr>
                                            <tr>
                                                <td class="rightAlign"><label class="checkoutLabel">Address - Line 2</label></td>
                                                <td><input class="checkout" id="addressLine2" name="addressLine2" size="25" type="text"></td>
                                            </tr>
                                            <tr>
                                                <td class="rightAlign"><label class="checkoutLabel">* City</label></td>
                                                <td><input class="regula-validation checkout" data-constraints="@Required(label=&quot;City&quot;, groups=[customer])" id="city" name="city" size="15" type="text"></td>
                                            </tr>
                                            <tr>
                                                <td class="rightAlign"><label class="checkoutLabel"><div id="stateRequired">* State</div></label></td>
                                                <td><select class="regula-validation checkout" data-constraints="@StateRequiredForSpecificCountries(countryFieldName=&quot;country&quot;, label=&quot;State&quot;, groups=[customer])" id="state" name="state" data-on="Component.Select"><option value="Lagos">Lagos</option></select></td>
                                            </tr>
                                            <tr>
                                                <td class="rightAlign"><label class="checkoutLabel">* Country</label></td>
                                                <td><select class="regula-validation checkout" data-constraints="@Required(label=&quot;Billing Country&quot;, groups=[customer])" id="country" name="country" data-on="Component.Select"><option value="Nigeria">Nigeria</option></select></td>
                                            </tr>
                                            <tr>
                                                <td class="rightAlign">* Phone Number</td>
                                                <td><input class="regula-validation checkout" data-constraints="@Required(label=&quot;Phone Number&quot;, groups=[customer])" id="phoneNumber" name="phoneNumber" size="25" type="text"></td>
                                            </tr>
                                            <tr>
                                                <td class="rightAlign">* Email Address</td>
                                                <td><input class="regula-validation checkoutBottom" data-constraints="@Required(label=&quot;Email Address&quot;, groups=[customer]) @Email(label=&quot;Email Address&quot;, groups=[customer])" id="emailAddress" name="emailAddress" size="15" type="text"></td>
                                            </tr>
                                            <tr>
                                                <td>&nbsp;</td>
                                            </tr>

                                        </tbody>
                                    </table>
                                </div>

                                <script type="text/javascript">jQuery(document).ready(function() {

                                var $country = jQuery('#country');

                                if ($country.val() == 'United States' || $country.val() == 'Canada') {
                                jQuery('#stateRequired').html('* State');
                                }

                                if ($country.length > 0 && "SELECT" == $country.get(0).tagName) {

                                $country.change(function() {

                                if ($country.val() == 'United States' || $country.val() == 'Canada') {
                                jQuery('#stateRequired').html('* State');
                                } else {
                                jQuery('#stateRequired').html('State');
                                }
                                });
                                }
                                });

                                jQuery('#addressLine1, #city, #zipCode, #country, #state').change(function() {
                                Infusion.Ecomm.OrderForms.submitFormUponChangeOnBilling('orderForm', 'Profit-Academy-2015--Payment-Plan', 'RENDER_ORDER_FORM');

                                });</script>
                            </div>


                            <div id="ORDER_FORM_SHIPPING_ENTRY">

                                <div id="orderFormShippingEntry">

                                </div>

                            </div>


                            <div id="SHIPPING_OPTIONS">

                                <div id="shippingOptionsContainer">

                                </div>
                            </div>

                            <div id="PAYMENT_PLANS">

                            </div>

                            <div id="ORDER_FORM_SUMMARY">

                                <table class="orderSummary tabular grid">
                                    <tbody>
                                        <tr>
                                            <th class="leftAlign">Summary Of What You Are Getting</th>
                                            <th class="rightAlign"></th>
                                        </tr>
                                        <tr>
                                            <td colspan="2">
                                                <img src="bonus.png">
                                            </td>
                                        </tr>
                                        <tr>
                                            <th class="leftAlign">Order Summary</th>
                                            <th class="rightAlign"></th>
                                        </tr>
                                        <tr>
                                            <td class="listCell">Subtotal</td>
                                            <td class="rightAlign">$80.00</td>
                                        </tr>
                                        <tr>
                                            <td class="subtotal">Total Due</td>
                                            <td class="rightAlign subtotal">$80.00</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>

 
                            <div id="PAYMENT_SELECTION">

                                <table class="paymentMethodTable tabular grid">
                                    <tbody>
                                       
                                        <tr>
                                            <td>
                                                <button type="submit" style="align-content: center"><img src="bbbbbb.png" alt="a"></button>
                                            </td>
                                        </tr>

                                                                           </tbody>
                                </table>
                            </div>

                        </b>
                    </div>

                    <b>
                        <br clear="all">

                            <div id="footer">

                                <div id="CUSTOM_HTML">

                                    <div id="customFooter">
                                        <!--<center><img src="./orderpage_files/payment-logos.jpg" alt="a"></center> --><br>
                                        <center>
                                            <font color="red">NOTICE: <i></i></font><i><font color="black"><b>Lorem ipsum, Please contact us at:  <a href="mailto:mail@mail.com">mail@mail.com</a></b></font></i><b>
                                            <br> <br>
                                            <font color="black"><b>Copyright © . All rights reserved.<br></b></font>
                                            <br>
                                            <br>
                                            <font color="black"><b> NEED HELP? Please contact us at:  <a href="mailto:mail@mail.com">mail@mail.com</a>  </b></font></b>
                                        </center>
                                        <b><font color="black"></font></b>
                                    </div>
                                    <b><font color="black"></font></b>
                                </div>
                                <b><font color="black"></font></b>
                            </div>
                        <b><font color="black"></font></b>
                    </b>
            </form>

I have tried editing severally but haven't been able to figure out what is wrong with the code.

Need help with this... thanks!

Your help is REALLY REALLY appreciated :)

Francis
  • 11
  • 3
  • 1
    you removed the echo from above your header which is why I closed the question, and failed to mark it as an edit. Now you're going to need to post your HTML form, because that is most likely where the problem is. Do that and I will reopen the question. – Funk Forty Niner Aug 01 '15 at 17:06
  • then this is unclear `$_POST['$inf_tTzSYWEgQfQ4dJf9'];` with the `$` in the array. It doesn't do anything I'll bet because of this mainly `if(isset($_POST['submit'])){` - so again, post your HTML form. – Funk Forty Niner Aug 01 '15 at 17:11
  • Hi, I have included the HTML from... can you take a look at it now please? Thanks. – Francis Aug 01 '15 at 18:40
  • the $_POST['$inf_tTzSYWEgQfQ4dJf9']; is just the name for the field – Francis Aug 01 '15 at 18:40
  • the big problem here is that nothing is being executed inside `if(isset($_POST['submit'])){...}` because you don't have a submit button with the name attribute for it. I.e. `name="submit"`. Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Aug 01 '15 at 18:41
  • I reopened the question, but I won't be posting an answer for it. I'll let that for others, or you to possibly fix it yourself. – Funk Forty Niner Aug 01 '15 at 18:42
  • Thanks a lot... I'll take a look at it again and see about fixing it myself. – Francis Aug 01 '15 at 18:50
  • Thank... working now... error was from the $inf_tTzSYWEgQfQ4dJf9. Realized it wasn't supposed to have the $. That makes it a variable. ...and naming the submit button submit It printing out the errors help A LOT! Waiting to see an email in my mailbox... – Francis Aug 01 '15 at 18:59
  • you're welcome and that's what I thought, as per what I mentioned in my comment above; it shouldn't have been there. `$` dollar signs have a special meaning in PHP. – Funk Forty Niner Aug 01 '15 at 19:01
  • I decided to post an answer after all, seeing I did all the initial troubleshooting. You can choose to mark it as solved if you wish, just so others are informed that a solution was found. – Funk Forty Niner Aug 01 '15 at 19:04

2 Answers2

0

It may not be working because your button isn't called "submit"

<button type="submit" style="align-content: center">

Try putting name = "submit" in there..

Plus, you could always put some debug in the php code, so it echo'd out what its doing to check values are what you thought.. Also, you set a bunch of variables and do nothing with it - didnt you mean to actually send the email?

BugFinder
  • 17,474
  • 4
  • 36
  • 51
  • [which is what I said...](http://stackoverflow.com/questions/31763288/submitting-form-to-email-and-redirecting-not-working?noredirect=1#comment51462010_31763288) and [the debug stuff too...](http://stackoverflow.com/questions/31763288/submitting-form-to-email-and-redirecting-not-working?noredirect=1#comment51462010_31763288) – Funk Forty Niner Aug 01 '15 at 18:50
0

$_POST['$inf_tTzSYWEgQfQ4dJf9']; with the $ in the array shouldn't be there, because of it being treated as another variable.

Then your submit button isn't named which is why your code isn't executing inside the first conditional statement.

You need to add the name attribute for it, as in name="submit".

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141