Jump to content

PHP Script to send HTML form information


fr33fr0mlif3

Recommended Posts

<tr>
									<td class="form"><form action="contact.php" method="post"><table border="0" cellpadding="0" cellspacing="0" style="margin-top:12px;">
										<tr>
											<td style="width:193px;"><table border="0" cellpadding="0" cellspacing="0">
												<tr><td><input type="text" name="yourname" value="your name:" onClick="this.value=''"></td></tr>
												<tr><td><input type="text" name="yourcompany" value="your company:" onClick="this.value=''" style="margin-top:6px;"></td></tr>
												<tr><td><input type="text" name="telephone" value="telephone:" onClick="this.value=''" style="margin-top:6px;"></td></tr>
												<tr><td><input type="text" name="email" value="e-mail:" onClick="this.value=''" style="margin-top:6px;"></td></tr>
											</table></td>
											<td><table border="0" cellpadding="0" cellspacing="0">
												<tr><td><textarea name="message" onClick="this.value=''" cols="2" rows="2">message:</textarea></td></tr>
												<tr>
													<td><table border="0" cellpadding="0" cellspacing="0" style="margin:0 0 0 75px;">
														<tr>
															<td style="width:50px;"><a href="#" onClick="document.getElementById('form1').reset()"><img alt="Reset Form"  src="images/kn_1.jpg" border="0"></a></td>
															<td><a href="#" onClick="document.getElementById('form1').submit()"><img alt="Submit Form"  src="images/kn_2.jpg" border="0"></a></td>
														</tr>
													</table></td>
												</tr>
											</table></td>
										</tr>
									</table></form></td>

 

I have been on the internet trying to find the best way to take care of this, I have tried asp cgi and php and I keep coming up with failure. The last one I have used is the code from about.com and here is what I have.

 

<?php

$SendFrom = "[email protected]"; 
$SendTo = "[email protected]"; 
$yourname = $_REQUEST['yourname'] ;
$yourcompany = $_REQUEST['yourcompany'] ;
$email = $_REQUEST['email'] ;
$telephone = $_REQUEST['telephone'] ;
$message = $_REQUEST['message'] ;

$fields = array();
$fields{"yourname"} = "Name";
$fields{"yourcompany"} = "Company";
$fields{"email"} = "Email";
$fields{"telephone"} = "Phone";
$fields{"message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: [email protected]";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us.

Somebody will get back to you as soon as possible, usualy within 24 hours. If you have any more questions, please consult our website at www.kilo-hosting.com.com";

if($email == '') {print "You have not entered an email, please go back and try again";}
else {
if($yourname == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.kilo-hosting.com/formthank.html" );}
else
{print "We encountered an error sending your mail, please notify [email protected]"; }
}
}
?>

 

I cannot figure out why this isn't working.

Link to comment
https://forums.phpfreaks.com/topic/58756-php-script-to-send-html-form-information/
Share on other sites

Where did you define $headers?

 

And you should use exit; after your header redirect. It will continue to process the page even after you call header(), then once it's done do the header(). A simple exit; will take care of that.

Where did you define $headers?

 

And you should use exit; after your header redirect. It will continue to process the page even after you call header(), then once it's done do the header(). A simple exit; will take care of that.

 

I am clueless about PHP. I am running off of tutorials. The form is not sending to the email address i have it set to.

 

{header( "Location: http://www.kilo-hosting.com/formthank.html" );}
exit;
else
{print "We encountered an error sending your mail, please notify [email protected]"; }
}
}
?>

 

proper location for exit; ?

Your first mail() function is trying to use a variable called $headers which I cannot find in the code you posted.

That's why I asked where it's defined.

 

I really don't know. I was looking for code correction. I am just trying to get this form to pull the information from the form and send it to my email address and have it divert them to a page that lets them know it sent successfully.

SO the correction may be to define the $headers variable and give it whatever values you want?

 

okay. once again. i dont know anything about php really. so what values can i define the headers? and fixing this header issue should fix the issue of it not sending the email out?

 

also is the rest of the code proper and should take the information in the html form and email it to me?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.