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.

this contact form is ALMOST WORKING!

Featured Replies

Hi,

 

I wanted to just thank everyone that has helped me on this board. but i have one more issue. i have a decent contact form php set up, and when i submit, it says that it's sent but i don't receive the email. (i have checked that the email address is correct and i have waited for hours for it to come so it shouldn't be those reasons.

 

could someone please let me know if something is wrong in the code? thanks!!! (by the way i am using a template in this one, that is why it's in table format. rest assured that i don't make table websites, i actually hate them).

 

oh and this is the website it's on www.myfashionoutlet.co.uk/contact.html - feel free to use the contact form as much as you like if you are messing around to try it. (the required fields aren't actually required so don't worry about that.)

 

would the fact that i have fields there which aren't utilised in my form.php be causing a problem?!?! ok i am going to shut up now. thank you!

 

<form method="post" action="form.php" id="contactform">
  <table width="100%" border="0" cellpadding="0" align="center" cellspacing="0">
                         <tr>
                           <td><table width="100%" border="0" cellpadding="4" cellspacing="1">
                               <tr>
                                 <td width="23%" align="Right"><b>Your 
                                   Name: <span class="style1">*</span></b></td>
                                 <td width="77%"><input type="text" name="name" style="width: 50%;">
                                 </td>
                               </tr>

                                 <td align="Right"><b>E-mail 
                                   Address: <span class="style1">*</span></b></td>
                                 <td><input type="text" name="email" style="width: 50%;"></td>
                               </tr>  <tr>
                                   <td align="Right"><b>Home Address: *</b></td>
                                   <td><input type="text" name="website2" style="width: 50%;"></td>
                                 </tr>
                                 <tr>
                                   <td align="Right"><b>Post Code:*</b></td>
                                   <td><input type="text" name="website2" style="width: 50%;"></td>
                                 </tr>
                                                             <tr>
                                                               <td align="Right"><b>Telephone:*</b></td>
                                                               <td><input type="text" name="website2" style="width: 50%;"></td>
                                                             </tr>
                               <tr>
                                 <td colspan="2" align="center">  <table width="369" border="0" cellpadding="0" cellspacing="6">
                                   <tr>
                                     <td width="369"><font size="1"><b> Questions: <span class="style1">* </span></b></font></td>
                                     </tr>
                                   <tr>
                                     <td><textarea name="message" rows="8" style="width: 94%;" wrap="VIRTUAL"></textarea></td>
                                     </tr>
                                   </table>
                                   <input type="submit" name="submit" value="Submit Form"></td>
                               </tr>
                           </table></td>
                         </tr>
                       </table>
                   </form>

 

 

 

and here is my form.php

 

<?php

if(!$_POST) exit;

$email = $_POST['email'];


//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ('name','email','message');
$required = array('name','email','message');

$your_email = "nlgdavies@gmail.com";
$email_subject = "New Message: ".$_POST['subject'];
$email_content = "new message:\n";

foreach($values as $key => $value){
  if(in_array($value,$required)){
	if ($key != 'subject' ) {
	  if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
	}
	$email_content .= $value.': '.$_POST[$value]."\n";
  }
}

if(@mail($your_email,$email_subject,$email_content)) {
	echo 'Message sent!'; 
} else {
	echo 'ERROR!';
}
}
?>

 

If anyone could help me on this i would be sooo grateful and i will love you forever!

  • Author

Hi!

 

Thanks for helping me. unfortunately that hasn't worked. do you think the subject part may be responsible for any problems?

 

like here...

 

foreach($values as $key => $value){
  if(in_array($value,$required)){
	if ($key != 'subject' ) { 

 

as there is no subject field in my html?

 

that's all i can think of as i am a noob with php!

 

thanks.

Hi!

 

Thanks for helping me. unfortunately that hasn't worked. do you think the subject part may be responsible for any problems?

 

like here...

 

foreach($values as $key => $value){
  if(in_array($value,$required)){
	if ($key != 'subject' ) { 

 

as there is no subject field in my html?

 

that's all i can think of as i am a noob with php!

 

thanks.

Yea try removing that or check your spam folder see if its going there

  • Author

oh sweet dude! they were going to by spam folder!!

 

thank you so much for your help man. i am really grateful for your advice.

 

thanks again!

  • Author

actually there is one more thing i wanted to know and then i promise i will leave you alone!

 

i am assuming that the php form looks for each value in the html form like <input type="text" name="email"> and shows the response in the resulting email when it's submitted.

 

so in the html you have

<input type="text" name="email">

in the form.php you have

$values = array ('name','email','message');

so when you recieve the email you get "email: your@email.com"

 

based on that logic i wanted to capture all the fields in the html and have them sent to my email. so i added

$values = array ('name','email','address','postcode','tel','message');

and i hoped that it would find name="home" etc.. and display them in the email but it's not working!

 

please could you explain to me how i can get all my fields to show in the email after submitting the form!

 

below is the code for my contact.html and form.php

 

THANK YOU SO MUCH FOR HELPING ME!!!

 

contact.html

 

<form method="post" action="form.php" id="contactform">
  <table width="100%" border="0" cellpadding="0" align="center" cellspacing="0">
                         <tr>
                           <td><table width="100%" border="0" cellpadding="4" cellspacing="1">
                               <tr>
                                 <td width="23%" align="Right"><b>Your 
                                   Name: <span class="style1">*</span></b></td>
                                 <td width="77%"><input type="text" name="name" style="width: 50%;">
                                 </td>
                               </tr>

                                 <td align="Right"><b>E-mail 
                                   Address: <span class="style1">*</span></b></td>
                                 <td><input type="text" name="email" style="width: 50%;"></td>
                               </tr>  <tr>
                                   <td align="Right"><b>Home Address: *</b></td>
                                   <td><input type="text" name="address" style="width: 50%;"></td>
                                 </tr>
                                 <tr>
                                   <td align="Right"><b>Post Code:*</b></td>
                                   <td><input type="text" name="postcode" style="width: 50%;"></td>
                                 </tr>
                                                             <tr>
                                                               <td align="Right"><b>Telephone:*</b></td>
                                                               <td><input type="text" name="tel" style="width: 50%;"></td>
                                                             </tr>
                               <tr>
                                 <td colspan="2" align="center">  <table width="369" border="0" cellpadding="0" cellspacing="6">
                                   <tr>
                                     <td width="369"><font size="1"><b> Questions: <span class="style1">* </span></b></font></td>
                                     </tr>
                                   <tr>
                                     <td><textarea name="message" rows="8" style="width: 94%;" wrap="VIRTUAL"></textarea></td>
                                     </tr>
                                   </table>
                                   <input type="submit" name="submit" value="Submit Form"></td>
                               </tr>
                           </table></td>
                         </tr>
                       </table>
                   </form>

 

form.php

 

<?php

if(!$_POST) exit;

$email = $_POST['email'];


//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
       $error.="Invalid email address entered";
       $errors=1;
}
if($errors==1) echo $error;
else{
       $values = array ('name','email','address','postcode','tel','message');
       $required = array('name','email','message');

       $your_email = "nlgdavies@gmail.com";
       $email_subject = "New Message: ".$_POST['subject'];
       $email_content = "new message:\n";

       foreach($values as $key => $value){
         if(in_array($value,$required)){
               if ($key != 'subject' ) {
                 if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
               }
               $email_content .= $value.': '.$_POST[$value]."\n";
         }
       }

       if(@mail($your_email,$email_subject,$email_content)) {
               echo 'Message sent!'; 
       } else {
               echo 'ERROR!';
       }
}
?>

 

 

:rolleyes:

Yea sure bro just do a variable for each field of ur form. like for a email and name field you would do

 

$name = (isset($_POST['name'])) ? $_POST['name'] : FALSE;
$email =  (isset($_POST['email'])) ? $_POST['email'] : FALSE;

 

And then in your message that you send to your email you would do this

 

$email_content = "Name: ".$name."";
$email_content .= "Email: ".$email."";

 

Hope this helped if it did +1 me if you like :) cheers

  • Author

hey,

 

Yeah i just gave you a plus one on all of your posts on this topic as you have been really helpful. i'm sorry to be a pain in the ass but i am having trouble putting what you said into practice. because of all the $value array my head is spinning and i can't work it out...

 

i tried doing this...

 

<?php

if(!$_POST) exit;

$email = $_POST['email'];


//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
       $error.="Invalid email address entered";
       $errors=1;
}
if($errors==1) echo $error;
else{
       $name = (isset($_POST['name'])) ? $_POST['name'] : FALSE;
	$email =  (isset($_POST['email'])) ? $_POST['email'] : FALSE;

       $required = array('name','email','message');

       $your_email = "nlgdavies@gmail.com";
       $email_subject = "New Message: ".$_POST['subject'];
       $email_content = "new message:\n";

       foreach($values as $key => $value){
         if(in_array($value,$required)){
               if ($key != 'subject' ) {
                 if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
               }


			$email_content = "Name: ".$name."";
$email_content .= "Email: ".$email."";"\n";
         }
       }

       if(@mail($your_email,$email_subject,$email_content)) {
               echo 'Message sent!'; 
       } else {
               echo 'ERROR!';
       }
}
?>

 

I think i messed it up. now it just sends an email saying "message:". php is so unforgiving, i have no idea what's going on! :bangb:

hey,

 

Yeah i just gave you a plus one on all of your posts on this topic as you have been really helpful. i'm sorry to be a pain in the ass but i am having trouble putting what you said into practice. because of all the $value array my head is spinning and i can't work it out...

 

i tried doing this...

 

<?php

if(!$_POST) exit;

$email = $_POST['email'];


//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
       $error.="Invalid email address entered";
       $errors=1;
}
if($errors==1) echo $error;
else{
       $name = (isset($_POST['name'])) ? $_POST['name'] : FALSE;
	$email =  (isset($_POST['email'])) ? $_POST['email'] : FALSE;

       $required = array('name','email','message');

       $your_email = "nlgdavies@gmail.com";
       $email_subject = "New Message: ".$_POST['subject'];
       $email_content = "new message:\n";

       foreach($values as $key => $value){
         if(in_array($value,$required)){
               if ($key != 'subject' ) {
                 if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
               }


			$email_content = "Name: ".$name."";
$email_content .= "Email: ".$email."";"\n";
         }
       }

       if(@mail($your_email,$email_subject,$email_content)) {
               echo 'Message sent!'; 
       } else {
               echo 'ERROR!';
       }
}
?>

 

I think i messed it up. now it just sends an email saying "message:". php is so unforgiving, i have no idea what's going on! :bangb:

 

 

<?php
$submit = (isset($_POST['submit'])) ? TRUE : FALSE;
if(!$submit){
exit("You have not submmitted the form please go back!");
}else{
$name = (isset($_POST['name'])) ? $_POST['name'] : FALSE;
$email = (isset($_POST['email'])) ? $_POST['email'] : FALSE;
$email_check = "/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i"; 
$errors = array();

if(!$name){
$errors[] = "Please enter your name!";
}
if(!$email){
$errors[] = "Please enter your email";
}
if($email){
if(!preg_match($email_check,$email)){
$errors[] = "The email you entered is not valid!";
}
}
if(count($errors) > 0){
foreach($errors AS $error){
echo "$error <br />";
}
}else{
$to = "Youremail@youremail.com";
$subject = "Your subject";

$email_content = "
Name: ".$name."\n\n
E-mail: ".$email."
";
$header = "From: <$to>";

if($mail = mail($to,$subject,$email_content,$header)){
echo "Email has been sent thank you!";
}else{
echo "Could not send email!";
}
}

}



?>



 

 

Ok there you go should work not tested yet if you have probs let me know :)

 

You may also try my more secure contact form here if you like cheers

 

Rizo Contact Form Mailer v1.5

  • Author

thanks dude,

 

i am plus 1ing you on the regular now. i'm gonna check your secure contact form out now as well.

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.