Hi,

I have just inherited a website with an existing contact us form. however, it isn't doing what is should and I can't work out why.

Does anyone know of a simple script with 4 fields (Name, Phone, Email and Comments) which I can simply insert into the existing contact us page.

i can post the existing code is neccessary.

regards

need alittle bit more info does it email or save to a database / and do you have a linux server ? and do you have pear installed >?

I would like to know what kind of database you are using, and where to is the message is sent.
you have several choices, depending on the storage method you intend to use ex: database, file, email to address....etc.

I would like to know what kind of database you are using, and where to is the message is sent.
you have several choices, depending on the storage method you intend to use ex: database, file, email to address....etc.

No Database. webserver is running linux with PHP v5 and. All I want is for the form to send an email to a particular email address.

<?php
//==========================================================================================================
// post variables (get the data)
//==========================================================================================================
$name1 = $_POST['name'];
$phone1 = $_POST['phone'];
$email1 = $_POST['email'];
$comment1 = $_POST['comment'];

//==========================================================================================================
// if name one is not empty make an email and send it
//==========================================================================================================

if ($name1) {
//==========================================================================================================
// need to have pear installed 
//==========================================================================================================
	require_once "Mail.php";


$from = "Admin <addyitcomefrom@yourwebsite.com>";
$to = "youremail@yourwebsite.com";
$subject = "subject goes here";
$body = "name: $name \n\n phone: $phone \n\n email: $email \n\n comment: $comment \\n";

$host = "mail.mailserver.com";
$username = "username";
$password = "password";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
	
}


//==========================================================================================================
// make table / form and such
//==========================================================================================================

echo "<form name='input' action='form.php' method='post'>
<p align='center'><table>
<tr>
	<td>NAME:</td>
	<td><input name='name' type='text' /></td>
</tr>
<tr>
	<td>PHONE:</td>
	<td><input name='phone' type='text' /></td>
</tr>
<tr>
	<td>EMAIL:</td>
	<td><input name='email' type='text' /></td>
</tr>
<tr>
	<td>COMMENTS:</td>
	<td><textarea name='comment' cols='10' rows='10' wrap='ON'></textarea></td>
</tr>
</table></p>
<p align='center'><input type='submit' /></p>
</form>";
?>

most linux systems do have pear installed if that doesnt work for you let me know and i will change it around

Yep, PEAR provides much more robust solution. But the native solution is as easy as this:

<?php
// Contact subject
$subject ="$subject";
// Details
$message="$detail";

// Mail of sender
$mail_from="$customer_mail";
// From
$header="from: $name <$mail_from>";

// Enter your email address
$to ='someone@somewhere.com';

$send_contact=mail($to,$subject,$message,$header);

// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>

i am aware but i had some issuse with the most simplest getting stuck on spam filters no idea why so when i made this one it auth to your email and goes with no problems

i am aware but i had some issuse with the most simplest getting stuck on spam filters no idea why so when i made this one it auth to your email and goes with no problems

Completely agreed

wow. great input guys.
I have included below what is already there. but when I try to submit the form I get a 'missing' message. even if all the fields are complete.
i'm not sure about pear.

here you go:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<script language="javascript" src="../fixflash.js"></script>

<head>

<?php


// MODIFY THE FOLLOWING SECTION

// your name
$recipientname = "Name";

// your email
$recipientemail = "info@domain.com";

// subject of the email sent to you
$subject = "Website Response for $recipientname";

// send an autoresponse to the user?
$autoresponse = "no";

// subject of autoresponse
$autosubject = "Thank you for your mail!";

// autoresponse message
$automessage = "This is an auto response to let you know that we've successfully received your email sent through 

our email form. Thanks! We'll get back to you shortly.";

// thankyou displayed after the user clicks "submit"
$thanks = "Thank you for contacting us.<br>We will get back to you as soon as possible.<br>";

// END OF NECESSARY MODIFICATIONS

?>

<style type="text/css"><!--
td,body,input,textarea {
	font-size:12px;
	font-family:Verdana,Arial,Helvetica,sans-serif;
	color:#000000}
--></style>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Titley</title>
</head>
<body background="images/stripes.gif" bgcolor="#ffffff" text="#000000" link="#000080" vlink="#800080" alink="#ff0000" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" onload="javascript:fixflash('nbn3.swf');">

<center>
<table width="760" height="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" bordercolor="#003399" background="images/bg.gif">
	<tr>
		<td height="230"><!--url's used in the movie-->
<!--text used in the movie-->
<div style="height:230px; width:760px;" id="nbn3.swf">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="760" height="230" id="nbn3.swf" align="middle" VIEWASTEXT>
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="nbn3.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="nbn3.swf" quality="high" bgcolor="#ffffff" width="760" height="230" name="nbn3.swf" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</div>	
</td>
	</tr>
	<tr>
	
	
		<td height="100%">
		
	<!--main content table-->	
		<table width="100%" height="100%" border="0" align="left" cellpadding="10" cellspacing="0" bordercolor="#008080" summary="">
	<tr>
	<td align="left" valign="top">
		<img src="images/header_contact.gif" border="0">
<br><br>

<center>
<img src="images/deckchair.gif" border="0">
</td>
		<td align="left" width="50%" valign="top"><font face="arial, helvetica" color="#000000" size="3">

		<br><br><br>
		<?php
if($_POST['submitform']) {

$Name = $HTTP_POST_VARS['Name'];
$Email = $HTTP_POST_VARS['Email'];
$Comments = $HTTP_POST_VARS['Comments'];

// check required fields
$dcheck = explode(",",$require);
while(list($check) = each($dcheck)) {
if(!$$dcheck[$check]) {
$error .= "Missing $dcheck[$check]<br>";
}
}

// check email address
if ((!ereg(".+\@.+\..+", $Email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $Email))){
$error .= "Invalid email address<br>";}

// display errors
if($error) {
?>

<b>Error</b><br>
<?php echo $error; ?><br>
<a href="#" onClick="history.go(-1)">try again</a>


<?php
}
else 
{

$browser = $HTTP_USER_AGENT;
$ip = $REMOTE_ADDR;

// format message
$message = "Online-Form Response for $recipientname:

Name: $Name
Email: $Email
Telephone: $telephone

Comments: $Comments

-----------------------------

Browser: $browser
User IP: $ip";

// send mail and print success message
mail($recipientemail,"$subject","$message","From: $Name <$Email>");

if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}

echo "$thanks";
}
} 
else {
?>

<form name="contactform" action="<?php echo $PHP_SELF; ?>" method="post">
<input type="hidden" name="require" value="Name,Email,Comments">
<table><tr> 
<td valign="top" align="right">Name:</td>
<td valign="top"><input name="Name" size="40"></td>
</tr><tr> 
<td valign="top" align="right">E-mail:</td>
<td valign="top"><input name="Email" size="40"></td>
</tr>
<tr> 
<td valign="top" align="right">Tel:</td>
<td valign="top"><input name="telephone" size="40"></td>
</tr>
<tr> 
<td valign="top" align="right">Message:</td>
<td valign="top"><textarea name="Comments" rows="15" cols="40"></textarea></td>
</tr><tr> 
<td colspan="2" align="right"><input type="submit" value="Submit" name="submitform">
<input type="reset" value="Reset" name="reset"></td>
</tr></table>
</form>
<?php } ?>
</font></td>
</tr>	

<tr> <td colspan="2">
<img src="images/map.gif" border="0">

</tr>
</table>
<!--end main content table-->	
</td>
	</tr>



<tr><td height="55" background="images/bot.gif">
&nbsp;<br>
<font face="arial, helvetica" color="#003399" size="2"><b>
Postal Address 
</b></font>
</td></tr>
</table>

</body>
</html>
if($_POST['submitform']) {

$Name = $HTTP_POST_VARS['Name'];
$Email = $HTTP_POST_VARS['Email'];
$Comments = $HTTP_POST_VARS['Comments'];

try this maybe instead

if($_POST['submitform']) {

$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Comments = $_POST['Comments'];

and put the [*code=php] [*/code]
around your code makes it easy on the eyes
just get rid of the * in the above line

Apologies for the code tags - i cant seem to go back and edit that post.
anyway, i made the changes you suggested and it didn't make any difference. still getting a 'missing' message when i submit the form. even though all the fields are complete.

Here is the code as it is now after your changes:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<script language="javascript" src="../fixflash.js"></script>

<head>

<?php


// MODIFY THE FOLLOWING SECTION

// your name
$recipientname = "Name";

// your email
$recipientemail = "info@domain.com";

// subject of the email sent to you
$subject = "Website Response for $recipientname";

// send an autoresponse to the user?
$autoresponse = "no";

// subject of autoresponse
$autosubject = "Thank you for your mail!";

// autoresponse message
$automessage = "This is an auto response to let you know that we've successfully received your email sent through 

our email form. Thanks! We'll get back to you shortly.";

// thankyou displayed after the user clicks "submit"
$thanks = "Thank you for contacting us.<br>We will get back to you as soon as possible.<br>";

// END OF NECESSARY MODIFICATIONS

?>

<style type="text/css"><!--
td,body,input,textarea {
font-size:12px;
font-family:Verdana,Arial,Helvetica,sans-serif;
color:#000000}
--></style>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Titley</title>
</head>
<body background="images/stripes.gif" bgcolor="#ffffff" text="#000000" link="#000080" vlink="#800080" alink="#ff0000" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" onload="javascript:fixflash('nbn3.swf');">

<center>
<table width="760" height="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" bordercolor="#003399" background="images/bg.gif">
<tr>
<td height="230"><!--url's used in the movie-->
<!--text used in the movie-->
<div style="height:230px; width:760px;" id="nbn3.swf">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="760" height="230" id="nbn3.swf" align="middle" VIEWASTEXT>
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="nbn3.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="nbn3.swf" quality="high" bgcolor="#ffffff" width="760" height="230" name="nbn3.swf" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</div> 
</td>
</tr>
<tr>


<td height="100%">

<!--main content table--> 
<table width="100%" height="100%" border="0" align="left" cellpadding="10" cellspacing="0" bordercolor="#008080" summary="">
<tr>
<td align="left" valign="top">
<img src="images/header_contact.gif" border="0">
<br><br>

<center>
<img src="images/deckchair.gif" border="0">
</td>
<td align="left" width="50%" valign="top"><font face="arial, helvetica" color="#000000" size="3">

<br><br><br>
<?php
if($_POST['submitform']) {

$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Comments = $_POST['Comments'];

// check required fields
$dcheck = explode(",",$require);
while(list($check) = each($dcheck)) {
if(!$$dcheck[$check]) {
$error .= "Missing $dcheck[$check]<br>";
}
}

// check email address
if ((!ereg(".+\@.+\..+", $Email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $Email))){
$error .= "Invalid email address<br>";}

// display errors
if($error) {
?>

<b>Error</b><br>
<?php echo $error; ?><br>
<a href="#" onClick="history.go(-1)">try again</a>


<?php
}
else 
{

$browser = $HTTP_USER_AGENT;
$ip = $REMOTE_ADDR;

// format message
$message = "Online-Form Response for $recipientname:

Name: $Name
Email: $Email
Telephone: $telephone

Comments: $Comments

-----------------------------

Browser: $browser
User IP: $ip";

// send mail and print success message
mail($recipientemail,"$subject","$message","From: $Name <$Email>");

if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}

echo "$thanks";
}
} 
else {
?>

<form name="contactform" action="<?php echo $PHP_SELF; ?>" method="post">
<input type="hidden" name="require" value="Name,Email,Comments">
<table><tr> 
<td valign="top" align="right">Name:</td>
<td valign="top"><input name="Name" size="40"></td>
</tr><tr> 
<td valign="top" align="right">E-mail:</td>
<td valign="top"><input name="Email" size="40"></td>
</tr>
<tr> 
<td valign="top" align="right">Tel:</td>
<td valign="top"><input name="telephone" size="40"></td>
</tr>
<tr> 
<td valign="top" align="right">Message:</td>
<td valign="top"><textarea name="Comments" rows="15" cols="40"></textarea></td>
</tr><tr> 
<td colspan="2" align="right"><input type="submit" value="Submit" name="submitform">
<input type="reset" value="Reset" name="reset"></td>
</tr></table>
</form>
<?php } ?>
</font></td>
</tr> 

<tr> <td colspan="2">
<img src="images/map.gif" border="0">

</tr>
</table>
<!--end main content table--> 
</td>
</tr>



<tr><td height="55" background="images/bot.gif">
&nbsp;<br>
<font face="arial, helvetica" color="#003399" size="2"><b>
Postal Address 
</b></font>
</td></tr>
</table>

</body>
</html>

hope you can help

run this and let me know

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<script language="javascript" src="../fixflash.js"></script>

<head>

<?php


// MODIFY THE FOLLOWING SECTION

// your name
$recipientname = "Name";

// your email
$recipientemail = "info@domain.com";

// subject of the email sent to you
$subject = "Website Response for $recipientname";

// send an autoresponse to the user?
$autoresponse = "no";

// subject of autoresponse
$autosubject = "Thank you for your mail!";

// autoresponse message
$automessage = "This is an auto response to let you know that we've successfully received your email sent through 

our email form. Thanks! We'll get back to you shortly.";

// thankyou displayed after the user clicks "submit"
$thanks = "Thank you for contacting us.<br>We will get back to you as soon as possible.<br>";

// END OF NECESSARY MODIFICATIONS

?>

<style type="text/css"><!--
td,body,input,textarea {
font-size:12px;
font-family:Verdana,Arial,Helvetica,sans-serif;
color:#000000}
--></style>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Titley</title>
</head>
<body background="images/stripes.gif" bgcolor="#ffffff" text="#000000" link="#000080" vlink="#800080" alink="#ff0000" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" onload="javascript<b></b>:fixflash('nbn3.swf');">

<center>
<table width="760" height="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" bordercolor="#003399" background="images/bg.gif">
<tr>
<td height="230"><!--url's used in the movie-->
<!--text used in the movie-->
<div style="height:230px; width:760px;" id="nbn3.swf">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="760" height="230" id="nbn3.swf" align="middle" VIEWASTEXT>
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="nbn3.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="nbn3.swf" quality="high" bgcolor="#ffffff" width="760" height="230" name="nbn3.swf" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</div> 
</td>
</tr>
<tr>


<td height="100%">

<!--main content table--> 
<table width="100%" height="100%" border="0" align="left" cellpadding="10" cellspacing="0" bordercolor="#008080" summary="">
<tr>
<td align="left" valign="top">
<img src="images/header_contact.gif" border="0">
<br><br>

<center>
<img src="images/deckchair.gif" border="0">
</td>
<td align="left" width="50%" valign="top"><font face="arial, helvetica" color="#000000" size="3">

<br><br><br>
<?php
$submitt = $_POST['submitform'];
if($submitt) {

$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Comments = $_POST['Comments'];

// check required fields
$dcheck = explode(",",$require);
while(list($check) = each($dcheck)) {
if(!$$dcheck[$check]) {
$error .= "Missing $dcheck[$check]<br>";
}
}

// check email address
if ((!ereg(".+\@.+\..+", $Email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $Email))){
$error .= "Invalid email address<br>";}

// display errors
if($error) {
?>

<b>Error</b><br>
<?php echo $error; ?><br>
<a href="#" onClick="history.go(-1)">try again</a>


<?php
}
else 
{

$browser = $HTTP_USER_AGENT;
$ip = $REMOTE_ADDR;

// format message
$message = "Online-Form Response for $recipientname:

Name: $Name
Email: $Email
Telephone: $telephone

Comments: $Comments

-----------------------------

Browser: $browser
User IP: $ip";

// send mail and print success message
mail($recipientemail,"$subject","$message","From: $Name <$Email>");

if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}

echo "$thanks";
}
} 
else {
?>

<form name="contactform" action="<?php echo $PHP_SELF; ?>" method="post">
<input type="hidden" name="require" value="Name,Email,Comments">
<table><tr> 
<td valign="top" align="right">Name:</td>
<td valign="top"><input name="Name" size="40"></td>
</tr><tr> 
<td valign="top" align="right">E-mail:</td>
<td valign="top"><input name="Email" size="40"></td>
</tr>
<tr> 
<td valign="top" align="right">Tel:</td>
<td valign="top"><input name="telephone" size="40"></td>
</tr>
<tr> 
<td valign="top" align="right">Message:</td>
<td valign="top"><textarea name="Comments" rows="15" cols="40"></textarea></td>
</tr><tr> 
<td colspan="2" align="right"><input type="submit" value="Submit" name="submitform">
<input type="reset" value="Reset" name="reset"></td>
</tr></table>
</form>
<?php } ?>
</font></td>
</tr> 

<tr> <td colspan="2">
<img src="images/map.gif" border="0">

</tr>
</table>
<!--end main content table--> 
</td>
</tr>



<tr><td height="55" background="images/bot.gif">
&nbsp;<br>
<font face="arial, helvetica" color="#003399" size="2"><b>
Postal Address 
</b></font>
</td></tr>
</table>

</body>
</html>

i changed two lines and ran it went with no problems but since your doing it with php takes alittle while to run if you were to use pear to email it would do it way faster

I've been on the phone sorry. - will try it now. incidently which 2 lines did you change?
cheers

Still cant get it to work in the live environment. same 'missing' message when i submit the form.
copied your code and still doesn't work. would it help if you had the live url ?

i see the error and i am not sure what is causing it the script that i posted was the one i moded from your post repost your whole script for the contact page which all / any changes you made and i'll put it on my test server and let you know

F.Y.I nice looking website

on second thought
comment out these lines and tell me if it works

// check required fields
$dcheck = explode(",",$require);
while(list($check) = each($dcheck)) {
if(!$$dcheck[$check]) {
$error .= "Missing $dcheck[$check]<br>";
}
}

it looks like in your code you dont have anything that fills or give any data to the $require on the explode code

on second thought
comment out these lines and tell me if it works

// check required fields
$dcheck = explode(",",$require);
while(list($check) = each($dcheck)) {
if(!$$dcheck[$check]) {
$error .= "Missing $dcheck[$check]<br>";
}
}

you mean comment out all 7 lines above?

it looks like in your code you dont have anything that fills or give any data to the $require on the explode code

Should this be referencing another file?
or how can i fix this?

that should have a file or a array that the explode would break into diffrent chunks but if you comment it out does the form work ok and submitt >?

Comments
Most Helpful

that should have a file or a array that the explode would break into diffrent chunks but if you comment it out does the form work ok and submitt >?

Genius. Yes the form is now sending as intended. Thanks for all your help.
regards

This question has already been answered. Start a new discussion instead.