Jump to content

php Contact Form Help


JonnyBoy2

Recommended Posts

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= "jm.horvatin@gmail.com";
//-----------------------------------------------------
//-----------------------------------------------------

$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 totalfitnessbc@gmail.com 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:totalfitnessbc@gmail.com">totalfitnessbc@gmail.com</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 totalfitnessbc@gmail.com 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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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= "jm.horvatin@gmail.com";
//-----------------------------------------------------
//-----------------------------------------------------

$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");
?>

Link to comment
Share on other sites

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= "jm.horvatin@gmail.com";
$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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.