Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Contact Form HELP!

Featured Replies

Hey everone, Im working on a new site at http://frontierbusiness.com/contact.html and for some reason the contact form is not working, can anyone tell me why? Its going to the error page for no reason, and I am not a php guru at all, does anyone know why? Thanks!!!

I really can't tell without the PHP code used to submit the form and the code used to handle the mailing function. Can you post it please. Thanks.

  • Author

<?php
$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$EmailTo = "jeff@frontierbusiness.com";
$Subject = "From Contact Page";
$Name = Trim(stripslashes($_POST['Name'])); 
$CompanyName = Trim(stripslashes($_POST['CompanyName'])); 
$PhoneNumber = Trim(stripslashes($_POST['PhoneNumber'])); 
$Fax = Trim(stripslashes($_POST['Fax'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$MailingAddress = Trim(stripslashes($_POST['MailingAddress'])); 
$ShippingAddress = Trim(stripslashes($_POST['ShippingAddress'])); 
$Subject = Trim(stripslashes($_POST['Subject'])); 
$Message = Trim(stripslashes($_POST['Message'])); 

// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
 print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
 exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "CompanyName: ";
$Body .= $CompanyName;
$Body .= "\n";
$Body .= "PhoneNumber: ";
$Body .= $PhoneNumber;
$Body .= "\n";
$Body .= "Fax: ";
$Body .= $Fax;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "MailingAddress: ";
$Body .= $MailingAddress;
$Body .= "\n";
$Body .= "ShippingAddress: ";
$Body .= $ShippingAddress;
$Body .= "\n";
$Body .= "Subject: ";
$Body .= $Subject;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

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

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

<form method="POST" action="contact.php">
<p class="top">Email From:<br>
<input type="text" name="EmailFrom">
<p>Name:<br>
<input type="text" name="Name">
<p>Company Name:<br>
<input type="text" name="CompanyName">
<p>Phone Number:<br>
<input type="text" name="PhoneNumber">
<p>Fax:<br>
<input type="text" name="Fax">
<p>Email:<br>
<input type="text" name="Email">
<p>Mailing Address:<br>
<input type="text" name="MailingAddress">
<p>Shipping Address (If different from mailing):<br>
<input type="text" name="ShippingAddress">
<p>Subject:<br>
<input type="text" name="Subject">
<p>Message:<br>
<textarea name="Message" cols="50" rows="6"></textarea>
<p><input type="submit" name="submit" value="Submit">
</form>

The first section of code which is handling the mail function, what file is that stored in? Is it your contact.php?

I would put your mail handling code in a separate file other than your contact form. I use something along these lines.

<?php
if(isset($_POST['e_mail'])) {
$to = "someone@someone.com"; 
$subject = "Website Design Liverpool Enquiry";
$from = $_POST['e_mail'];
$title = $_POST['title'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$e_mail = $_POST['e_mail'];
$telephone_number = $_POST['telephone_number'];
$message = $_POST['message'];
$body = "Request From:\n \n Title: $title\n First Name: $first_name\n Last Name: $last_name\n Telephone Number: $telephone_number\n Email: $e_mail\n Message: $message\n "; 
echo "<h2>Thank you $title $last_name,</h2><p>message</p>";
mail($to, $subject, $body, "From: $from");
$to = $e_mail;
$subject = "Reply from Someone";
$body = "$title $first_name $last_name,

Thank you for your enquiry. 

Kind Regards

Someone";
$headers = 'From: something@something.com'; 
mail($to, $subject, $body, $headers); 
} else { 
echo "All fields in bold must be completed. Thank you." ;} 
?>

 

Hope this helps. I'm too tired to go in to it now I'm afraid I have a busy day tomorrow. If this doesn't help I'll check back in tomorrow at some point.

It should be part of PHP.

 

Create a blank PHP page (eg. test.php) and inside put the following:

<?php phpinfo(); ?>

 

You should be able to see if mail's installed from there.

silly question but have you put the contact.php in your root dir (same location as contact.html),

Ya its in the same spot as the index.html

Hi

 

I am getting page not found when I submit your form, are you working on it.

who is your host.

 

Pat

lol and:

ok.htm, and error.htm in same loc

and all are in lower case?

and ok.htm is ok.htm not ok.html :)

 

if so try:

 

// redirect to success page
if ($success){
 header("Location: ok.htm");
}
else{
 header("Location: error.htm");
}

instead, i'd imagin it'd be better as you are instructing the php (still server side to redirect) rather than printing a command from php to be interprited by the browser to redirect via another http request back to retrieve another page.

 

(cut out the middle man)

  • Author

Im sorry its a clients FTP and I cant send it over, if it was mine i would have no problem at all, can you tell me what to do?? Thanks so much!

the code works fine

 

http://174.132.104.66/~websnob/

 

its a server setting, must be.

 

whats your hosting situation, dedicated, vps etc?

 

do you have any software on that server that sends emails out?

 

[EDIT: i have changed the code abit though... but nothing that would fix the script sending a meta refresh]

 

[EDIT 2: upon reading the above edit comment i realised i actually got rid of the meta refresh and changed it to force the Location http header... same thing~]

the reason it is failing on your site is because of this

[code: ive edited the code a tad but it functions the same and using a better redirect method, in my opinion]
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
header("Location: ok.htm");
exit();
}
else{
header("Location: error.htm");
  exit();
}

 

the mail() function is return a false value meaning the second part of the if/else statement comes into play, on your version it prints out a meta refresh

 

so thats where it is failing, the next step is to figure out why or contact yahoo, i would read the yahoo hosting docs and see if they dont let mail() function on the servers, if they dont in that exact same place there will be a link with what they do let you use...

 

NOTE:

my hosting account is less than 12 hours old and my host wont let my account send out emails untill 12 hours old so even though my test worked the server is blocking my emails at a higher level, and you wont get a email from my test

just been thinking about it, blocking the mail() function would be really evil... its just got to be broke, your going to have to contact yahoo i think... we need someone else to run this code and check it works for them to... because if so its definatly a server thing.

 

in the php.ini file you can select the mailing software you want... but ive never used yahoo hosting before so dont know what level of horrible we talking about.

 

maybe advise the client to go with hostgator hosting.. $14.99/mo dedicated ip + free private ssl... gotta be better than horrible hosting!

those files working for you?

 

I have recieved mail from it, just change mailto back to your email address and check your junk mail box after sending

  • Author

YESSSSSSSSSSSSSSSSS YESSSSSSSSSSSSSSS YESSSSSSSSSSS SUCCCCCCCCCCCCCCCESSSSSSSSSSSSSSSSS HAHAHAHAH lol my god! I finally got it all i had to do was put my domain in the from field! Thanks A Ton for everyones help!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.