Jump to content

simple php contact form - Problems with code


websime

Recommended Posts

Hey guys,

The curious thing about this situation is that I am using virtually the same code (html, css, and php) on a contact form for another site and it works perfectly.

For some reason, I can't seem to get it to work on this site:

http://www.namastenutrition.net/form.htm

 

The form loads fine and it is accessing the php file, but everytime I fill it out and click submit, it loads the error2.html page and does not email me the information.

 

Any help would be most appreciated!!!

 

HTML:

<form id="myform" class="cssform" method="POST" action="php/contact.php">
<fieldset>
<legend>To contact me, simply fill out this form!</legend>

<p>
<label for="user">Name</label>
<input type="text" id="user" name="Name" value="" />
</p>

<p>
<label for="phonenumber">Phone Number:</label>
<input type="text" id="phonenumber" name="Phonenumber" value="" />
</p>

<p>
<label for="emailaddress">Email Address:</label>
<input type="text" id="emailaddress" name="Email" value="" />
</p>

<p>
<label for="regarding">Regarding:</label>
<input type="text" id="regarding" name="Regarding" value="" />
</p>

<p>
<label for="comments">Questions or Comments:</label>
<textarea id="comments" name="Comments" rows="5" cols="25"></textarea>
</p>


<div style="margin-left: 150px;">
<input type="submit" name="submit" value="Submit" class="submit"> <input type="reset" name="clear" value="Clear" class="clear">
</div>
</fieldset>
</form>

 

PHP:

<?php
// get posted data into local variables
$Email = Trim(stripslashes($_POST['Email'])); 
$EmailTo = "bentsime@gmail.com";
$Subject = "User Contact - Contact Page";
$Name = Trim(stripslashes($_POST['Name'])); 
$Phonenumber = Trim(stripslashes($_POST['Phonenumber'])); 
$Regarding = Trim(stripslashes($_POST['Regarding'])); 
$Comments = Trim(stripslashes($_POST['Comments'])); 

// validation
$validationOK=true;
if (Trim($Email)=="") $validationOK=false;
if (Trim($Name)=="") $validationOK=false;
if (Trim($Comments)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../error2.html\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Phonenumber: ";
$Body .= $Phonenumber;
$Body .= "\n";
$Body .= "Regarding: ";
$Body .= $Regarding;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $Comments;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$Email>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../thanks2.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../error2.html\">";
}
?>

Link to comment
Share on other sites

Thanks to all 3 of you for your quick replies!

 

I replaced that

$success = mail($EmailTo, $Subject, $Body, "From: <".$Email.">");

and I changed the first error to error1.html...

 

result:

error2.html is triggered.

 

as for echo'ing the 3 variables to make sure they are not empty...unfortunately I have no clue what that means! 

Care to enlighten me?

 

 

html code is the same

here is the new php

<?php
// get posted data into local variables
$Email = Trim(stripslashes($_POST['Email'])); 
$EmailTo = "bentsime@gmail.com";
$Subject = "User Contact - Contact Page";
$Name = Trim(stripslashes($_POST['Name'])); 
$Phonenumber = Trim(stripslashes($_POST['Phonenumber'])); 
$Regarding = Trim(stripslashes($_POST['Regarding'])); 
$Comments = Trim(stripslashes($_POST['Comments'])); 

// validation
$validationOK=true;
if (Trim($Email)=="") $validationOK=false;
if (Trim($Name)=="") $validationOK=false;
if (Trim($Comments)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../error1.html\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Phonenumber: ";
$Body .= $Phonenumber;
$Body .= "\n";
$Body .= "Regarding: ";
$Body .= $Regarding;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $Comments;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <".$Email.">");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../thanks2.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../error2.html\">";
}
?>

 

Link to comment
Share on other sites

okay here's some easy questions:

1.  what is looool??

 

2. Does anyone know if GoDaddy supports php? 

I am diggin thru my client's account and don't see it stated anywhere that they do. 

 

3.  They DO support asp.  Can anyone point me to a site where I can get a simple asp mail script and learn more about it?

 

thanks!

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.