Jump to content

[SOLVED] TROUBLESHOOTING: Can some PLEASE help me with this script?


Xelex

Recommended Posts

I'm currently developing a contact form for a business and I've ran into a bit of a problem....

 

I wrote this script:

 

<?php

if ($_POST["email"]<>'') {

$ToEmail = '[email protected]';

$EmailSubject = 'Ready Rental Contact Form';

$mailheader = "From: ".$_POST["[email protected]"]."\r\n";

$mailheader .= "Reply-To: ".$_POST["[email protected]"]."\r\n";

$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";

$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";

$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";

$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>";

mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure. AGAIN.");

?>

Your message was sent

<?php

} else {

?>

 

            <td width="468"><form action="contact_us_div.php" method="post">

<table width="400" border="0" cellspacing="2" cellpadding="0">

<tr>

<td width="29%" class="bodytext">Customer First Name:</td>

<td width="71%"><input name="name" type="text" id="name" size="32"></td>

</tr>

<tr>

<td width="29%" class="bodytext">Customer Last Name:</td>

<td width="71%"><input name="name" type="text" id="name" size="32"></td>

</tr>

<tr>

<td width="29%" class="bodytext">Affiliation/Convention:</td>

<td width="71%"><input name="name" type="text" id="name" size="32"></td>

</tr>

<tr>

<td class="bodytext">Customer Home Number:</td>

<td><input name="email" type="text" id="email" size="32"></td>

</tr>

<tr>

<td width="29%" class="bodytext">Customer Cell Number:</td>

<td width="71%"><input name="name" type="text" id="name" size="32"></td>

</tr>

<tr>

<td width="29%" class="bodytext">Customer Work Number:</td>

<td width="71%"><input name="name" type="text" id="name" size="32"></td>

</tr>

<tr>

<td width="29%" class="bodytext">Dates for Rental:</td>

<td width="71%"><input name="name" type="text" id="name" size="32"></td>

</tr>

<tr>

                <td nowrap="nowrap"><span class="style19"><font face="Verdana" color="#000000">Type of Equipment Needed</font></span></td>

                <td><select name="FieldData7">

                  <option value="Power Wheelchair">Power Wheelchair</option>

 

                  <option value="Power Scooter">Power Scooter</option>

                  <option value="Other">Other</option>

                </select>

                </td>

              </tr>

<tr>

<td class="bodytext">Addtional Comments:</td>

<td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td>

</tr>

<tr>

<td class="bodytext"> </td>

<td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td>

</tr>

</table>

</form>

<?php

};

?>

 

But it returns an error everytime I run it...

I'm using Yahoo as a server, and I set up the PHP email to [email protected] as requested by Yahoo, but when I try to use the form, it returns an error...

 

I'm a relative novice at PHP, and I'm curious as to what's wrong.... Can you troubleshoot the script for me, by chance?

please remember code tags otherwise we cant read it

<?php 
if ($_POST["email"]<>'') { 
   $ToEmail = '[email protected]'; 
   $EmailSubject = 'Ready Rental Contact Form'; 
   $mailheader = "From: ".$_POST["[email protected]"]."\r\n"; 
   $mailheader .= "Reply-To: ".$_POST["[email protected]"]."\r\n"; 
   $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
   $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
   $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
   $MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>"; 
   mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure. AGAIN."); 
?> 
Your message was sent
<?php 
} else { 
?> 

            <td width="468"><form action="contact_us_div.php" method="post"> 
<table width="400" border="0" cellspacing="2" cellpadding="0"> 
<tr> 
<td width="29%" class="bodytext">Customer First Name:</td> 
<td width="71%"><input name="name" type="text" id="name" size="32"></td> 
</tr> 
<tr> 
<td width="29%" class="bodytext">Customer Last Name:</td> 
<td width="71%"><input name="name" type="text" id="name" size="32"></td> 
</tr> 
<tr> 
<td width="29%" class="bodytext">Affiliation/Convention:</td> 
<td width="71%"><input name="name" type="text" id="name" size="32"></td> 
</tr> 
<tr> 
<td class="bodytext">Customer Home Number:</td> 
<td><input name="email" type="text" id="email" size="32"></td> 
</tr> 
<tr> 
<td width="29%" class="bodytext">Customer Cell Number:</td> 
<td width="71%"><input name="name" type="text" id="name" size="32"></td> 
</tr> 
<tr> 
<td width="29%" class="bodytext">Customer Work Number:</td> 
<td width="71%"><input name="name" type="text" id="name" size="32"></td> 
</tr> 
<tr> 
<td width="29%" class="bodytext">Dates for Rental:</td> 
<td width="71%"><input name="name" type="text" id="name" size="32"></td> 
</tr> 
<tr>
                <td nowrap="nowrap"><span class="style19"><font face="Verdana" color="#000000">Type of Equipment Needed</font></span></td>
                <td><select name="FieldData7">
                  <option value="Power Wheelchair">Power Wheelchair</option>

                  <option value="Power Scooter">Power Scooter</option>
                  <option value="Other">Other</option>
                </select>
                </td>
              </tr>
<tr> 
<td class="bodytext">Addtional Comments:</td> 
<td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td> 
</tr> 
<tr> 
<td class="bodytext"> </td> 
<td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td> 
</tr> 
</table> 
</form>
<?php 
}; 
?>

 

 

also whats the error?

you overwrite your get value here:

 

<td width="29%" class="bodytext">Customer Last Name:</td> 
<td width="71%"><input name="name" type="text" id="name" size="32"></td> 
</tr> 
<tr> 
<td width="29%" class="bodytext">Affiliation/Convention:</td> 
<td width="71%"><input name="name" type="text" id="name" size="32"></td> 

It doesn't actually give me a code error, it just says failure.

 

And I think I know what you mean by overwriting my value, out of laziness I didn't rewrite the input call, I just copy pasted the same line over and over again...

 

So I take it I should change the id names to something else and then repost them under their respect names in the top line of code?

 

Also, thanks a lot for the fast responses guys, I really appreciate having you alleviate my stupidity xD

 

Sorry about the code tags, it's been a while since I've actually posted on a programming forum =\.

Here's a contact form that I use on one of my websites, maybe you could modify yours to work with this code:

 

The HTML (just take out the CSS, unless you would like me to send that to you as well):

<form action='forms/contact/process.php' method='post' enctype='multipart/form-data' name="Contact" id="Contact" class="cmxform">
			<p>Please complete the form below. Mandatory fields marked <em>*</em></p>
			<fieldset>
  					<legend>Contact Information</legend>
  						<ol>
						<li><label for="First">First:<em>*</em></label> <input type="text" name='First' id='First' tabindex='1' /></li>
						<li><label for="Last">Last:<em>*</em></label> <input type="text" name='Last' id='Last' tabindex='2' /></li>
						<li><label for="Email">E-Mail:<em>*</em></label> <input type="text" name='Email' id='Email' tabindex='3' /></li>
						<li><label for="Phone">Phone:</label>  <input type="text" name='Phone' id='Phone' tabindex='4' /></li>
						<li><label for="Address">Address:</label> <input type="text" name='Address' id='Address' tabindex='5' /></li>
						<li><label for="City">City:</label> <input type="text" name='City' id='City' tabindex='6' /></li>
						<li><label for="State">State:</label> <select size='1' name='State' id='State' tabindex='7'>
							<option value="">Select Below</option><option value="AL">Alabama</option>
							<option value="AK">Alaska</option><option value="AZ">Arizona</option>
							<option value="AR">Arkansas</option><option value="CA">California</option>
							<option value="CO">Colorado</option><option value="CT">Connecticut</option>
							<option value="DE">Delaware</option><option value="FL">Florida</option>
							<option value="GA">Georgia</option><option value="HI">Hawaii</option>
							<option value="ID">Idaho</option><option value="IL">Illinois</option>
							<option value="IN">Indiana</option><option value="IA">Iowa</option>
							<option value="KS">Kansas</option><option value="KY">Kentucky</option>
							<option value="LA">Louisiana</option><option value="ME">Maine</option>
							<option value="MD">Maryland</option><option value="MA">Massachusetts</option>
							<option value="MI">Michigan</option><option value="MN">Minnesota</option>
							<option value="MS">Mississippi</option><option value="MO">Missouri</option>
							<option value="MT">Montana</option><option value="NE">Nebraska</option>
							<option value="NV">Nevada</option><option value="NH">New Hampshire</option>
							<option value="NJ">New Jersey</option><option value="NM"> New Mexico </option>
							<option value="NY">New York</option><option value="NC">North Carolina</option>
							<option value="ND">North Dakota</option><option value="OH">Ohio</option>
							<option value="OK">Oklahoma</option><option value="OR">Oregon</option>
							<option value="PA">Pennsylvania</option><option value="PR">Puerto Rico</option>
							<option value="RI">Rhode Island</option><option value="SC">South Carolina</option>
							<option value="SD"> South Dakota </option><option value="TN">Tennessee</option>
							<option value="TX">Texas</option> <option value="UT">Utah</option>
							<option value="VT">Vermont</option><option value="VA">Virginia</option>
							<option value="WA">Washington</option><option value="DC">Washington, D.C.</option>
							<option value="WV">West Virginia</option><option value="WI">Wisconsin</option>
							<option value="WY">Wyoming </option></select></li>
						<li><label for="Zip">Zip: <em>*</em></label> <input type="text" name='Zip' id='Zip' tabindex="8" /></li>							
						<li>
							<fieldset>
								<legend>Please leave your comments below:<em>*</em></legend>
									<label for="Comments">Comments:</label> <textarea name='comments' id='Comments' rows="7" cols="45"  tabindex='9'></textarea>
							</fieldset>
    						</li>
						 </ol>
					<p class="small">By submitting this form with your telephone number you are consenting for xxxxxxx and all 
					authorized representatives to contact you even if your name is on a Federal or State "Do not call List".</p>
					<p class="small">Thank you for submitting your information. I will be in contact with you by phone or email.</p> 

				<p><input name="submit" type="submit" value='Submit Form' />       
				<input name="reset" type="reset" value='Reset Form' /></p>
			</fieldset>
		</form>

 

Here's the processor.php:

<?php

include("db_config.php");

function pt_register()
{
  $num_args = func_num_args();
   $vars = array();

   if ($num_args >= 2) {
       $method = strtoupper(func_get_arg(0));

       if (($method != 'SESSION') && ($method != 'GET') && ($method != 'POST') && ($method != 'SERVER') && ($method != 'COOKIE') && ($method != 'ENV')) {
           die('The first argument of pt_register must be one of the following: GET, POST, SESSION, SERVER, COOKIE, or ENV');
     }

       $varname = "HTTP_{$method}_VARS";
      global ${$varname};

       for ($i = 1; $i < $num_args; $i++) {
           $parameter = func_get_arg($i);

           if (isset(${$varname}[$parameter])) {
               global $$parameter;
               $$parameter = ${$varname}[$parameter];
          }

       }

   } else {
       die('You must specify at least two arguments');
   }

}

$errors=0;
$error="The following errors occured while processing your form input.<ul>";

pt_register('POST','First');
pt_register('POST','Last');
pt_register('POST','Email');
pt_register('POST','Phone');
pt_register('POST','Address');
pt_register('POST','City');
pt_register('POST','State');
pt_register('POST','Zip');
pt_register('POST','comments');
$comments=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $comments);if($First=="" || $Last=="" || $Email=="" || $comments=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";

}

if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$Email)){
$error.="<li>Invalid email address entered";
$errors=1;
}

$email = '[email protected]';
$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
if($errors==1) echo $error;

else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Name: ".$First." ".$Last."
Email: ".$Email."
Phone: ".$Phone."
Address: ".$Address."
City: ".$City."
State: ".$State."
Zip: ".$Zip."
Comments: ".$comments."

Submitted from IP: ".$ip."
";
$First = mysql_escape_string($_POST['First']);
$Last = mysql_escape_string($_POST['Last']);
$Email = mysql_escape_string($_POST['Email']);
$Phone = mysql_escape_string($_POST['Phone']);
$Address = mysql_escape_string($_POST['Address']);
$City = mysql_escape_string($_POST['City']);
$State = mysql_escape_string($_POST['State']);
$Zip = mysql_escape_string($_POST['Zip']);
$comments = mysql_escape_string($_POST['comments']);

$message = htmlspecialchars($message);
$headers = "MIME-Version: 1.0";
$headers .= "Content-type: text/plain";
mail("[email protected]","New contact information submitted at your website",$message,"From: ".$email.",$headers,");
$link = mysql_connect("$DHost","$DUser","$DPass");
mysql_select_db("$DBase",$link);
$query="insert into contacts (First,Last,Email,Phone,Address,City,State,Zip) values ('".$First."','".$Last."','".$Email."','".$Phone."','".$Address."','".$City."','".$State."','".$Zip."')";
mysql_query($query);
header("Refresh: 0;url=http://www.yourdomain.com/sent.htm");
?>

<?php 
}
?>

Here's a contact form that I use on one of my websites, maybe you could modify yours to work with this code:

 

The HTML (just take out the CSS, unless you would like me to send that to you as well):

<form action='forms/contact/process.php' method='post' enctype='multipart/form-data' name="Contact" id="Contact" class="cmxform">
			<p>Please complete the form below. Mandatory fields marked <em>*</em></p>
			<fieldset>
  					<legend>Contact Information</legend>
  						<ol>
						<li><label for="First">First:<em>*</em></label> <input type="text" name='First' id='First' tabindex='1' /></li>
						<li><label for="Last">Last:<em>*</em></label> <input type="text" name='Last' id='Last' tabindex='2' /></li>
						<li><label for="Email">E-Mail:<em>*</em></label> <input type="text" name='Email' id='Email' tabindex='3' /></li>
						<li><label for="Phone">Phone:</label>  <input type="text" name='Phone' id='Phone' tabindex='4' /></li>
						<li><label for="Address">Address:</label> <input type="text" name='Address' id='Address' tabindex='5' /></li>
						<li><label for="City">City:</label> <input type="text" name='City' id='City' tabindex='6' /></li>
						<li><label for="State">State:</label> <select size='1' name='State' id='State' tabindex='7'>
							<option value="">Select Below</option><option value="AL">Alabama</option>
							<option value="AK">Alaska</option><option value="AZ">Arizona</option>
							<option value="AR">Arkansas</option><option value="CA">California</option>
							<option value="CO">Colorado</option><option value="CT">Connecticut</option>
							<option value="DE">Delaware</option><option value="FL">Florida</option>
							<option value="GA">Georgia</option><option value="HI">Hawaii</option>
							<option value="ID">Idaho</option><option value="IL">Illinois</option>
							<option value="IN">Indiana</option><option value="IA">Iowa</option>
							<option value="KS">Kansas</option><option value="KY">Kentucky</option>
							<option value="LA">Louisiana</option><option value="ME">Maine</option>
							<option value="MD">Maryland</option><option value="MA">Massachusetts</option>
							<option value="MI">Michigan</option><option value="MN">Minnesota</option>
							<option value="MS">Mississippi</option><option value="MO">Missouri</option>
							<option value="MT">Montana</option><option value="NE">Nebraska</option>
							<option value="NV">Nevada</option><option value="NH">New Hampshire</option>
							<option value="NJ">New Jersey</option><option value="NM"> New Mexico </option>
							<option value="NY">New York</option><option value="NC">North Carolina</option>
							<option value="ND">North Dakota</option><option value="OH">Ohio</option>
							<option value="OK">Oklahoma</option><option value="OR">Oregon</option>
							<option value="PA">Pennsylvania</option><option value="PR">Puerto Rico</option>
							<option value="RI">Rhode Island</option><option value="SC">South Carolina</option>
							<option value="SD"> South Dakota </option><option value="TN">Tennessee</option>
							<option value="TX">Texas</option> <option value="UT">Utah</option>
							<option value="VT">Vermont</option><option value="VA">Virginia</option>
							<option value="WA">Washington</option><option value="DC">Washington, D.C.</option>
							<option value="WV">West Virginia</option><option value="WI">Wisconsin</option>
							<option value="WY">Wyoming </option></select></li>
						<li><label for="Zip">Zip: <em>*</em></label> <input type="text" name='Zip' id='Zip' tabindex="8" /></li>							
						<li>
							<fieldset>
								<legend>Please leave your comments below:<em>*</em></legend>
									<label for="Comments">Comments:</label> <textarea name='comments' id='Comments' rows="7" cols="45"  tabindex='9'></textarea>
							</fieldset>
    						</li>
						 </ol>
					<p class="small">By submitting this form with your telephone number you are consenting for xxxxxxx and all 
					authorized representatives to contact you even if your name is on a Federal or State "Do not call List".</p>
					<p class="small">Thank you for submitting your information. I will be in contact with you by phone or email.</p> 

				<p><input name="submit" type="submit" value='Submit Form' />       
				<input name="reset" type="reset" value='Reset Form' /></p>
			</fieldset>
		</form>

 

Here's the processor.php:

<?php

include("db_config.php");

function pt_register()
{
  $num_args = func_num_args();
   $vars = array();

   if ($num_args >= 2) {
       $method = strtoupper(func_get_arg(0));

       if (($method != 'SESSION') && ($method != 'GET') && ($method != 'POST') && ($method != 'SERVER') && ($method != 'COOKIE') && ($method != 'ENV')) {
           die('The first argument of pt_register must be one of the following: GET, POST, SESSION, SERVER, COOKIE, or ENV');
     }

       $varname = "HTTP_{$method}_VARS";
      global ${$varname};

       for ($i = 1; $i < $num_args; $i++) {
           $parameter = func_get_arg($i);

           if (isset(${$varname}[$parameter])) {
               global $$parameter;
               $$parameter = ${$varname}[$parameter];
          }

       }

   } else {
       die('You must specify at least two arguments');
   }

}

$errors=0;
$error="The following errors occured while processing your form input.<ul>";

pt_register('POST','First');
pt_register('POST','Last');
pt_register('POST','Email');
pt_register('POST','Phone');
pt_register('POST','Address');
pt_register('POST','City');
pt_register('POST','State');
pt_register('POST','Zip');
pt_register('POST','comments');
$comments=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $comments);if($First=="" || $Last=="" || $Email=="" || $comments=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";

}

if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$Email)){
$error.="<li>Invalid email address entered";
$errors=1;
}

$email = '[email protected]';
$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
if($errors==1) echo $error;

else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Name: ".$First." ".$Last."
Email: ".$Email."
Phone: ".$Phone."
Address: ".$Address."
City: ".$City."
State: ".$State."
Zip: ".$Zip."
Comments: ".$comments."

Submitted from IP: ".$ip."
";
$First = mysql_escape_string($_POST['First']);
$Last = mysql_escape_string($_POST['Last']);
$Email = mysql_escape_string($_POST['Email']);
$Phone = mysql_escape_string($_POST['Phone']);
$Address = mysql_escape_string($_POST['Address']);
$City = mysql_escape_string($_POST['City']);
$State = mysql_escape_string($_POST['State']);
$Zip = mysql_escape_string($_POST['Zip']);
$comments = mysql_escape_string($_POST['comments']);

$message = htmlspecialchars($message);
$headers = "MIME-Version: 1.0";
$headers .= "Content-type: text/plain";
mail("[email protected]","New contact information submitted at your website",$message,"From: ".$email.",$headers,");
$link = mysql_connect("$DHost","$DUser","$DPass");
mysql_select_db("$DBase",$link);
$query="insert into contacts (First,Last,Email,Phone,Address,City,State,Zip) values ('".$First."','".$Last."','".$Email."','".$Phone."','".$Address."','".$City."','".$State."','".$Zip."')";
mysql_query($query);
header("Refresh: 0;url=http://www.yourdomain.com/sent.htm");
?>

<?php 
}
?>

 

Thank you a TON for the help...

I got it working =)

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.