JonnyBoy2 Posted April 8, 2012 Share Posted April 8, 2012 Hey everyone, I have a really simple php contact form that I managed to mess up and can't for the life of me figure out what the problem is. It accepts the responses and will continue to the "success" page like it's supposed to, but it doesn't mail the data from the form fields when it does. I was hoping you'd be able to take a look and maybe find the error(s)... I know it's probably something really simple and stupid but I can't figure it out. Thanks in advance!! <?php //----------------------------------------------------- //----------------------------------------------------- $address= "[email protected]"; //----------------------------------------------------- //----------------------------------------------------- $firstname = $_REQUEST["First Name: "]; $lastname = $_REQUEST["Last Name: "]; $phone = $_REQUEST["Phone Number: "]; $referred = $_REQUEST["I was referred by: "]; $address = $_REQUEST["Address: "]; $city = $_REQUEST["City: "]; $province = $_REQUEST["Province: "]; $postal = $_REQUEST["Postal Code: "]; $email = $_REQUEST["Email Address: "]; $mime_boundary = md5(time()); $headers = "From: $name <$email>\n"; $headers .= "Reply-To: $subject <$email>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n"; $message = "--$mime_boundary\n\n"; $message .= "New Web Registration: \n\n\n"; $message .= "First Name: $firstname \n\n"; $message .= "Last Name: $lastname \n\n"; $message .= "Phone Number: $phone \n\n"; $message .= "I was referred by: $referred \n\n"; $message .= "Address: $address \n\n"; $message .= "City: $city \n\n"; $message .= "Province: $province \n\n"; $message .= "Postal Code: $postal \n\n"; $message .= "Email Address: $email \n\n"; $message .= "--$mime_boundary--\n\n"; $mail_sent = mail($address, $subject, $message, $headers); header("location:paypal.html"); ?> ?> <form action="get_mail.php" method="POST" class="contactform"> <p>First Name <input name="firstname" type="text" / class="box" value="" size="35"> Last Name <input name="lastname" type="text" class="box" value="" size="40"/> <br> Phone <input name="phonenumber" type="text" value="" class="box"> I was referred by <input name="referred" type="text" class="box" value="" size="45"> <br> Address <input name="address" type="text" class="box" value="" size="35"> City <input name="city" type="text" class="box" value="" size="20"> Province <input name="province" type="text" class="box" value="" size="7"> Postal Code <input name="postal" type="text" class="box" value="" size="6"> Email Address <input name="email" type="text" class="box" value="" size="40"> <br> <br> Automatic month-to-month: This is a month-to-month program and is considered active and ongoing until cancelled as described in the Cancellation policy. CANCELLATION POLICY: ShapeIt! member must give notice of cancellation by Email to [email protected] at least 5 business days from the above stated debit date. Even if you notify your instructor, you still are required to send and email to <a href="mailto:[email protected]">[email protected]</a> Save a record of this email to serve as your cancellation receipt. 30-day money back guarantee is contingent upon receiving an email of cancelation to [email protected] within the first 30 days of signing this agreement.</p> <p><br> I certify that I have fully read and understand the terms of this Agreement and will comply with the contents herein. Prepay memberships are non-refundable after the 30 day money back guarantee period expires. <br> <br> <input type="submit" class="contactform" value="Proceed to Payment" target="_blank"> <br class="clear" /> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/260570-php-contact-form-help/ Share on other sites More sharing options...
NLT Posted April 8, 2012 Share Posted April 8, 2012 Where is this script located? Is it on a local server (like XAMPP) or on a web host? Quote Link to comment https://forums.phpfreaks.com/topic/260570-php-contact-form-help/#findComment-1335415 Share on other sites More sharing options...
dcro2 Posted April 8, 2012 Share Posted April 8, 2012 POST/GET info is stored in the $_REQUEST variable by their input names (i.e. <input name="firstname">) $firstname = $_REQUEST['firstname']; $lastname = $_REQUEST['lastname']; //etc Quote Link to comment https://forums.phpfreaks.com/topic/260570-php-contact-form-help/#findComment-1335420 Share on other sites More sharing options...
JonnyBoy2 Posted April 8, 2012 Author Share Posted April 8, 2012 It's stored on a web host server. Quote Link to comment https://forums.phpfreaks.com/topic/260570-php-contact-form-help/#findComment-1335433 Share on other sites More sharing options...
dcro2 Posted April 8, 2012 Share Posted April 8, 2012 Is your problem that NO email gets sent or that the email contains no info? See my last post for the second one. Quote Link to comment https://forums.phpfreaks.com/topic/260570-php-contact-form-help/#findComment-1335434 Share on other sites More sharing options...
JonnyBoy2 Posted April 8, 2012 Author Share Posted April 8, 2012 No email seems to be sent. I've built these before but they are always much simpler with less fields. Was a little confused because there was no errors and it moves to the success page... :/ Quote Link to comment https://forums.phpfreaks.com/topic/260570-php-contact-form-help/#findComment-1335448 Share on other sites More sharing options...
dcro2 Posted April 8, 2012 Share Posted April 8, 2012 Is this form on the same host where you've gotten it to work previously? You don't check whether the mail() call was successful or not, so getting to the success page doesn't really mean anything. This host just might have it disabled. Quote Link to comment https://forums.phpfreaks.com/topic/260570-php-contact-form-help/#findComment-1335451 Share on other sites More sharing options...
JonnyBoy2 Posted April 8, 2012 Author Share Posted April 8, 2012 Good point. And yep, have used this before on this same host. Am I to understand then that there isn't anything blatantly incorrect about how it's coded? I test all my work on the same server and it has always allowed it. Maybe they've adjusted in the last two weeks. As fate as I know FatCow supports it. No obvious problems so far? (thanks again for taking the time to help me with this, I was getting totally lost). Quote Link to comment https://forums.phpfreaks.com/topic/260570-php-contact-form-help/#findComment-1335465 Share on other sites More sharing options...
dcro2 Posted April 8, 2012 Share Posted April 8, 2012 The only obvious thing was: POST/GET info is stored in the $_REQUEST variable by their input names (i.e. <input name="firstname">) $firstname = $_REQUEST['firstname']; $lastname = $_REQUEST['lastname']; //etc But that shouldn't in theory prevent the email from being sent, it would just be mostly blank. You should try removing the Location header and turning error reporting on if possible at the top of your script. error_reporting(0); ini_set('display_errors', 1); If mail() does fail it will return false, but there's not really any way to know what went wrong without checking the mail logs on the system itself. Maybe you could try with a mailer class like SwiftMailer or PHPMailer. EDIT: just thought I should mention, try using \r\n for the headers instead of just \n and check your junk folder. Quote Link to comment https://forums.phpfreaks.com/topic/260570-php-contact-form-help/#findComment-1335471 Share on other sites More sharing options...
JonnyBoy2 Posted April 9, 2012 Author Share Posted April 9, 2012 Yep, not showing up in the junk and have added those \r\n\ to the headers. I will admit I really don't grasp php, but is there anything in the below that looks wrong now? Thanks for all the help, if this fails, do you know of where I could provide the field names and have the php generated / created for me? I'm covering someone else and at this point I need to get this working, even if I have to hire someone to write the php for me. :-\ <?php //----------------------------------------------------- //----------------------------------------------------- $address= "[email protected]"; //----------------------------------------------------- //----------------------------------------------------- $firstname = $_REQUEST['firstname']; $lastname = $_REQUEST['lastname']; $phone = $_REQUEST['phone']; $referred = $_REQUEST['referred']; $address = $_REQUEST['address']; $city = $_REQUEST['city']; $province = $_REQUEST['province']; $postal = $_REQUEST['postal']; $email = $_REQUEST['email']; $mime_boundary = md5(time()); $headers = "From: $name <$email>\r\n"; $headers = "Reply-To: $subject <$email>\r\n"; $headers = "MIME-Version: 1.0\r\n"; $headers = "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\r\n"; $message = "--$mime_boundary\n\n"; $message = "New Web Registration: \n\n\n"; $message = "First Name: $firstname \n\n"; $message = "Last Name: $lastname \n\n"; $message = "Phone Number: $phone \n\n"; $message = "I was referred by: $referred \n\n"; $message = "Address: $address \n\n"; $message = "City: $city \n\n"; $message = "Province: $province \n\n"; $message = "Postal Code: $postal \n\n"; $message = "Email Address: $email \n\n"; $message = "--$mime_boundary--\n\n"; $mail_sent = mail($address, $subject, $message, $headers); header("location:paypal.html"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/260570-php-contact-form-help/#findComment-1335674 Share on other sites More sharing options...
dcro2 Posted April 9, 2012 Share Posted April 9, 2012 I should have noticed this before... you named both your to email address and your form input for address as $address. That causes mail() to fail. Also, you should be appending each line instead of overwriting the last. <?php //----------------------------------------------------- //----------------------------------------------------- $toemail= "[email protected]"; $subject = "Your subject"; //----------------------------------------------------- //----------------------------------------------------- $firstname = $_REQUEST['firstname']; $lastname = $_REQUEST['lastname']; $phone = $_REQUEST['phone']; $referred = $_REQUEST['referred']; $address = $_REQUEST['address']; $city = $_REQUEST['city']; $province = $_REQUEST['province']; $postal = $_REQUEST['postal']; $email = $_REQUEST['email']; $mime_boundary = md5(time()); $headers = "From: $firstname $lastname <$email>\r\n"; $headers .= "MIME-Version: 1.0\r\n"; //notice the dot before =, that means to concatenate $headers .= "Content-Type: multipart/alternative; boundary=$mime_boundary\r\n"; $message = "--$mime_boundary\n\n"; $message .= "New Web Registration: \n\n\n"; $message .= "First Name: $firstname \n\n"; $message .= "Last Name: $lastname \n\n"; $message .= "Phone Number: $phone \n\n"; $message .= "I was referred by: $referred \n\n"; $message .= "Address: $address \n\n"; $message .= "City: $city \n\n"; $message .= "Province: $province \n\n"; $message .= "Postal Code: $postal \n\n"; $message .= "Email Address: $email \n\n"; $message .= "--$mime_boundary--\n\n"; $mail_sent = mail($toemail, $subject, $message, $headers); if($mail_sent) header("location: paypal.html"); else die("Please try again"); ?> Honestly, you don't even need to do the mime boundary stuff since you're only sending plain text. And therefore the only header you should need is From. Quote Link to comment https://forums.phpfreaks.com/topic/260570-php-contact-form-help/#findComment-1335692 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.