...

View Full Version : PHP form/email help



MManning
03-22-2009, 07:31 PM
Hi all,

I'm somewhat new to the world of php and my brother has asked me to help him with his web site. i've been working on a way to send form information by e-mail. Simple enough, but for some reason it just isn't working.

This is the form which I see no problem with.


<FORM action="http://www.dormpaper.com/orderform.php" method="post">

<LABEL for="firstname">First Name: </LABEL><br>
<INPUT type="text" id="firstname"><p>
<LABEL for="lastname">Last Name: </LABEL><br>
<INPUT type="text" id="lastname"><p>
<LABEL for="email">E-mail Address: </LABEL><br>
<INPUT type="text" id="email"><p>
<LABEL for="heightft">Height: </LABEL><br>
<INPUT type="text" id="heightft" size="5"> feet
<LABEL for="heightin"></LABEL>
<INPUT type="text" id="heightin" size="5"> inches <p>
<LABEL for="widthft">Width: </LABEL><br>
<INPUT type="text" id="widthft" size="5"> feet
<LABEL for="widthin"></LABEL>
<INPUT type="text" id="widthin" size="5"> inches <p>
<LABEL for="comments">Comments: </LABEL><br>
<TEXTAREA id="comments" rows="10" cols="50"></TEXTAREA><p>
<LABEL for="image">Upload Image: <LABEL>
<INPUT type="file" id="image"><p>
<INPUT type="submit" value="Submit!">

</FORM>

I can't seem to figure out the problem. I've tried to take the (.) out of the ($_REQUEST['whatever']) and it hasn't worked. I think I also have the attachment wrong, it seems like too little for an attachment.


<?php
$to = "orders@dormpaper.com";
$subject = "New Order";
$body = .$_REQUEST['firstname']."\n";
$body .= .$_REQUEST['lastname']."\n";
$body .= .$_REQUEST['email']."\n";
$body .= .$_REQUEST['heightft']."\n";
$body .= .$_REQUEST['heightin']."\n";
$body .= .$_REQUEST['widthft']."\n";
$body .= .$_REQUEST['widthin']."\n";
$body .= .$_REQUEST['comments'].;
$fileatt = .$_REQUEST['image'].;
mail($to, $subject, $body, $fileatt)
?>

Any help would be greatly appreciated.

steelaz
03-22-2009, 07:44 PM
No need for dot next to $_REQUEST.

Also you can't just include image like that, first you have to upload it and then properly add it: http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php

MManning
03-22-2009, 07:57 PM
I changed it, but it still doesn't seem to work. It brings me to the page, but when I check the email, it doesn't show up.



<?php
$to = "orders@dormpaper.com";
$subject = "New Order";
$body = $_REQUEST['firstname']"\n";
$body .= $_REQUEST['lastname']"\n";
$body .= $_REQUEST['email']"\n";
$body .= $_REQUEST['heightft']"\n";
$body .= $_REQUEST['heightin']"\n";
$body .= $_REQUEST['widthft']"\n";
$body .= $_REQUEST['widthin']"\n";
$body .= $_REQUEST['comments'];
mail($to, $subject, $body)
?>

Also, after going to that page, when I click "View Source", it shows up as:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>


I'm not sure if that is an issue, but I would think it is.

timgolding
03-22-2009, 08:10 PM
Im suprised that works surely you need a semicolon after mail($to, $subject, $body)

to become


mail($to, $subject, $body);


Anyway have you checked your spam folder in your email. Sometimes mail sent from a webserver without any additional headers in this way is automatically set to spam.

You could try making a page with



<?PHP
mail("tgold_69@yahoo.com", "Hello", "Hello");
?>


and I'll tell you if it comes through.

MManning
03-22-2009, 08:20 PM
I put the semicolon in, but it still doesn't work. I tested it and I got an e-mail, but I cannot seem to figure out why the code isn't working.

timgolding
03-22-2009, 08:43 PM
try


print_r($_REQUEST);


somewhere in your code to make sure the request data is working. I wonder what would happen if you tried



mail("tgold_69@yahoo.com", "hello", "");


in other words tried sending a mail with the body completely blank would it send? not sure.

Try



echo $body;


Just before the mail funtion to see if body is NULL.

finally you can add



if(mail($to, $subject, $body))
{
echo "mail sent";
}
else
{
echo "mail not sent";
}


The mail function returns false if there was a problem sending your mail.

timgolding
03-22-2009, 08:54 PM
Ignore all that it looks like theres a syntax problem is in your code

Your Code:


<?php
$to = "orders@dormpaper.com";
$subject = "New Order";
$body = $_REQUEST['firstname']"\n";
$body .= $_REQUEST['lastname']"\n";
$body .= $_REQUEST['email']"\n";
$body .= $_REQUEST['heightft']"\n";
$body .= $_REQUEST['heightin']"\n";
$body .= $_REQUEST['widthft']"\n";
$body .= $_REQUEST['widthin']"\n";
$body .= $_REQUEST['comments'];
mail($to, $subject, $body)
?>


Correction



<?php
$to = "orders@dormpaper.com";
$subject = "New Order";
$body = $_REQUEST['firstname']."\n";
$body .= $_REQUEST['lastname']."\n";
$body .= $_REQUEST['email']."\n";
$body .= $_REQUEST['heightft']."\n";
$body .= $_REQUEST['heightin']."\n";
$body .= $_REQUEST['widthft']."\n";
$body .= $_REQUEST['widthin']."\n";
$body .= $_REQUEST['comments'];
mail($to, $subject, $body)
?>


Its the dots you need after the requests.

I guess you must have error reporting turned off on your server or it would show you your syntax problems.

MManning
03-22-2009, 09:05 PM
I tried that and it still does not work for some reason. COuld it have somethign to do with the form.

timgolding
03-22-2009, 09:11 PM
Sorry i missed the semi colon after the mail again

try this



<?php
$to = "orders@dormpaper.com";
$subject = "New Order";
$body = $_REQUEST['firstname']."\n";
$body .= $_REQUEST['lastname']."\n";
$body .= $_REQUEST['email']."\n";
$body .= $_REQUEST['heightft']."\n";
$body .= $_REQUEST['heightin']."\n";
$body .= $_REQUEST['widthft']."\n";
$body .= $_REQUEST['widthin']."\n";
$body .= $_REQUEST['comments'];
mail($to, $subject, $body);
?>

timgolding
03-22-2009, 10:14 PM
actually the form is wrong also
should be


<FORM action="http://www.dormpaper.com/orderform.php" method="post">

<LABEL for="firstname">First Name: </LABEL><br>
<INPUT type="text" id="firstname" name="firstname"><p>
<LABEL for="lastname">Last Name: </LABEL><br>
<INPUT type="text" name="lastname" id="lastname"><p>
<LABEL for="email">E-mail Address: </LABEL><br>
<INPUT type="text" id="email" name="email"><p>
<LABEL for="heightft">Height: </LABEL><br>
<INPUT type="text" id="heightft" size="5" name="heightft"> feet
<LABEL for="heightin"></LABEL>
<INPUT type="text" id="heightin" size="5" name="heightin"> inches <p>
<LABEL for="widthft">Width: </LABEL><br>
<INPUT type="text" id="widthft" size="5" name="widthft"> feet
<LABEL for="widthin"></LABEL>
<INPUT type="text" id="widthin" size="5" name="widthin"> inches <p>
<LABEL for="comments">Comments: </LABEL><br>
<TEXTAREA id="comments" rows="10" cols="50" name="comments"></TEXTAREA><p>
<LABEL for="image">Upload Image: <LABEL>
<INPUT type="file" id="image"><p>
<INPUT type="submit" value="Submit!">

</FORM>


You need the name attribute for all the form elements to pass it on through post.

MManning
03-24-2009, 01:46 AM
I don't know why but it still is not working. It's very frustrating, but thank you for your help so far. I'll take break from it and play aorund with it later on.

rafiki
03-24-2009, 03:33 AM
Did you add print_r($_REQUEST); and also since you know the data is coming from the POST method why not change all the $_REQUEST's to $_POST's?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum