Jump to content

[SOLVED] Super easy question - please help


binarygirl

Recommended Posts

hi there.. I have a very basic form that is not working.. can someone please help.  I have both the thankyou.html and the error.html files on the server so they are not missing.

 

Basic form.. name, phone, email and message. 

 

here is the HTML:

 

  <form method="post" action="sendmail.php">

  <p>

  <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2">name*</font><br>

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

    <br>

    <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2">phone*</font><br>

    <input name="phone" type="text" id="phone">

    <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2">

    <br>  email*</font>                              <br>

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

      <br>

      <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2">questions/comments</font><br>

    <textarea name="message" cols="35" rows="7" id="message"></textarea>

    <br>

    <input type="submit" name="Submit" value="send"></form>

</p>

and here is the sendmail.php

 

<?

if (empty($email) || empty($name) || empty($phone))

{

  header( "Location: error.html" );

}

else

{

 

  //mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

 

  $admin = '[email protected]' ;

  $name = stripslashes($_REQUEST['name']) ;

  $message = stripslashes($_REQUEST['message']) ;

  $email = stripslashes($_REQUEST['email']) ;

  $phone = stripslashes($_REQUEST['phone']) ;

 

  mail( $admin, "Feedback: $name", "Name: $name\nPhone: $phone\nEmail: $email\n\n$message", "From: $name <$email>" );

 

 

  $subject = 'Online Inquiry';

  $replymsg = 'Thank you for your email inquiry. One of our staff will respond shortly.' ;

  mail( $email, $subject, $replymsg , "From: $admin" );

 

  header( "Location: thankyou.html" );

}

?>

 

 

It should send me an email, them and email and give an error if they dont fill out name, phone & email fields... What am I doing wrong??  :((((  soooooooo frustrating  - can someone please help?

 

 

Link to comment
https://forums.phpfreaks.com/topic/101500-solved-super-easy-question-please-help/
Share on other sites

Where are your $_POST's?

 

To be more specific, you need to define your $email, $name, etc:

 

if (empty($_POST['email']l) || empty($_POST['name']) || empty($_POST['phone'])

or

<?php
if (isset($_POST['Submit'])) {
   $email = $_POST['email']);
   $name = $_POST['name']);
   $phone = $_POST['phone']);
}

--then run your code.

 

try this:

 

 

<?php
if (empty($email) ||empty($name)||empty($phone)||!isset($phone)||!isset($name)||!isset($email))
{
  header( "Location: error.html" );
}
else  if(!empty($name)||!empty($email)||!empty($phone)||isset($name)||isset($phone)||isset($email))
{

  //mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

  $admin = '[email protected]' ; 
  $name = stripslashes($_POST['name']) ;
  $message = stripslashes($_POST['message']) ;
  $email = stripslashes($_POST['email']) ;
  $phone = stripslashes($_POST['phone']) ;

  mail( $admin, "Feedback: $name", "Name: $name\nPhone: $phone\nEmail: $email\n\n$message", "From: $name <$email>" );


  $subject = 'Online Inquiry';
  $replymsg = 'Thank you for your email inquiry. One of our staff will respond shortly.' ; 
  mail( $email, $subject, $replymsg , "From: $admin" );

  header( "Location: thankyou.html" );
}
?>

I tried darkfreak's and I couldn't get past the error page.. just saw your's ben.. maybe I copied it wrong or missed something in the paste... but I get a blank page again...

 

this is my first form.. can ya tell ? :)

 

I copied it from another source and have just been trying to alter it to fit what I need. 

Not working... all I get is a blank page. Fields filled in or not.  :(

 

<?php
if (isset($_POST['Submit'])) {
   $email = $_POST['email']);
   $name = $_POST['name']);
   $phone = $_POST['phone']);
}

if (empty($email) || empty($name) || empty($phone))
{
  header( "Location: error.html" );
}
else 
{

  //mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

  $admin = '[email protected]' ; 
  $name = stripslashes($_REQUEST['name']) ;
  $message = stripslashes($_REQUEST['message']) ;
  $email = stripslashes($_REQUEST['email']) ;
  $phone = stripslashes($_REQUEST['phone']) ;

  mail( $admin, "Feedback: $name", "Name: $name\nPhone: $phone\nEmail: $email\n\n$message", "From: $name <$email>" );


  $subject = 'Online Inquiry';
  $replymsg = 'Thank you for your email inquiry. One of our staff will respond shortly.' ; 
  mail( $email, $subject, $replymsg , "From: $admin" );

  header( "Location: thankyou.html" );
}
?>

I don't have a server to test it, but try:

<form method="post" action="sendmail.php">
<p>
<font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2">name*</font>
<input name="name" type="text" id="name">
<font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2">phone*</font>
<input name="phone" type="text" id="phone">
     <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2">email*</font>                             
<input name="email" type="text" id="email">
<font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2">questions/comments</font>
<textarea name="message" cols="35" rows="7" id="message"></textarea>
<input type="submit" name="btnSubmit" value="send"></form>
</p>

<?php
if (isset($_POST['btnSubmit'])) {
   $name =  stripslashes($_POST['name']));
   $phone = stripslashes($_POST['phone']));
   $email = stripslashes($_POST['email']));
   $message = stripslashes($_POST['message']));
}

if (empty($name) || empty($phone) || empty($email) || empty($message))
{
  header( "Location: error.html" );
}
else
{
  //mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
  $admin = '[email protected]' ;
  mail( $admin, "Feedback: $name", "Name: $name\nPhone: $phone\nEmail: $email\n\n$message", "From: $name <$email>" );
  $subject = 'Online Inquiry';
  $replymsg = 'Thank you for your email inquiry. One of our staff will respond shortly.' ;
  mail( $email, $subject, $replymsg , "From: $admin" );

  header( "Location: thankyou.html" );
}
?>

Try now:

 

 

<?php
if (empty($email) ||empty($name)||empty($phone)||!isset($phone)||!isset($name)||!isset($email))
{
 header( "Location: error.html" );
 exit;
}
else  if(!empty($name)||!empty($email)||!empty($phone)||isset($name)||isset($phone)||isset($email))
{

 //mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

 $admin = '[email protected]' ; 
 $name = stripslashes($_POST['name']) ;
 $message = stripslashes($_POST['message']) ;
 $email = stripslashes($_POST['email']) ;
 $phone = stripslashes($_POST['phone']) ;

 mail( $admin, "Feedback: $name", "Name: $name\nPhone: $phone\nEmail: $email\n\n$message", "From: $name <$email>" );


 $subject = 'Online Inquiry';
 $replymsg = 'Thank you for your email inquiry. One of our staff will respond shortly.' ; 
 mail( $email, $subject, $replymsg , "From: $admin" );

 header( "Location: thankyou.html" );
 exit;
}
?>

try echoing the thank you message instead of having it redirect to another page ;)

 

 

<?php
if (empty($email) ||empty($name)||empty($phone)||!isset($phone)||!isset($name)||!isset($email))
{
  header( "Location: error.html" );
 
}
else  if(!empty($name)||!empty($email)||!empty($phone)||isset($name)||isset($phone)||isset($email))
{

  //mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

  $admin = '[email protected]' ; 
  $name = stripslashes($_POST['name']) ;
  $message = stripslashes($_POST['message']) ;
  $email = stripslashes($_POST['email']) ;
  $phone = stripslashes($_POST['phone']) ;

  mail( $admin, "Feedback: $name", "Name: $name\nPhone: $phone\nEmail: $email\n\n$message", "From: $name <$email>" );


  $subject = 'Online Inquiry';
  $replymsg = 'Thank you for your email inquiry. One of our staff will respond shortly.' ; 
  mail( $email, $subject, $replymsg , "From: $admin" );
echo " Thank You for signing up!";
}
?>

I am just copying and pasting your code DFs... you took out the exits...  I don't get past the error.html  never have. 

I would rather use the thankyou.html that a blank page with thank you. 

 

Sorry.. I thought it was an easy question :-\

 

(I tried yours too Ben.. just saw that post .. it didnt work either I got the blank (sendmail.php) page again thanls though  appreciate your time :()

if it were up to me id get rid of the headers and echo everything  :P

 

 

Try:

 

 

 

<?php
if (empty($email) ||empty($name)||empty($phone)||!isset($phone)||!isset($name)||!isset($email))
{
echo "Please Fill in the form!";

}
else  if(!empty($name)||!empty($email)||!empty($phone)||isset($name)||isset($phone)||isset($email))
{

  //mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

  $admin = '[email protected]' ; 
  $name = stripslashes($_POST['name']) ;
  $message = stripslashes($_POST['message']) ;
  $email = stripslashes($_POST['email']) ;
  $phone = stripslashes($_POST['phone']) ;

  mail( $admin, "Feedback: $name", "Name: $name\nPhone: $phone\nEmail: $email\n\n$message", "From: $name <$email>" );


  $subject = 'Online Inquiry';
  $replymsg = 'Thank you for your email inquiry. One of our staff will respond shortly.' ; 
  mail( $email, $subject, $replymsg , "From: $admin" );
echo " Thank You for signing up!";
}
?>

Try starting simple, get it to work, then add the rest of your code:

 

oh and don't forget to change the name of your form submit button to btnSubmit

 

<?php
if (isset($_POST['btnSubmit'])) {
$name =  stripslashes($_POST['name']));
$phone = stripslashes($_POST['phone']));
$email = stripslashes($_POST['email']));
$message = stripslashes($_POST['message']));

if (empty($name)) {
	print "error";
	//header( "Location: error.html" );
} else {
	print "thank you";
//header( "Location: thankyou.html" );
} //if empty
} //if isset
?>

then your post data is either empty ot not submitted :P

 

 

Modified:

 

<?php
if (empty($email) ||empty($name)||empty($phone))
{
echo "Please Fill in the form!";

}
else  if(!empty($name)||!empty($email)||!empty($phone)||isset($name)||isset($phone)||isset($email))
{

  //mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

  $admin = '[email protected]' ; 
  $name = stripslashes($_POST['name']) ;
  $message = stripslashes($_POST['message']) ;
  $email = stripslashes($_POST['email']) ;
  $phone = stripslashes($_POST['phone']) ;

  mail( $admin, "Feedback: $name", "Name: $name\nPhone: $phone\nEmail: $email\n\n$message", "From: $name <$email>" );


  $subject = 'Online Inquiry';
  $replymsg = 'Thank you for your email inquiry. One of our staff will respond shortly.' ; 
  mail( $email, $subject, $replymsg , "From: $admin" );
echo " Thank You for signing up!";
}
?>  

its not working guys.. I am lost.  All I wanted was name, phone, email and message to be sent to me... error.html if name, phone and email were blank.. and thank you when they click submit...

 

I found a script that was name, subject, email and message.. and changed subject to phone...  I think this is over my head.

 

this is my HTML which I think is fine...

 

 <form method="post" action="sendmail.php">
					    <p>
					      <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2">name*</font><br>
					      <input name="name" type="text" id="name">
					      <br>
					      <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2">phone*</font><br>
					      <input name="phone" type="text" id="phone">
					      <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2"><br>
					      email*</font>                              <br>
                              <input name="email" type="text" id="email">
                              <br>
                              <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2">questions/comments</font><br>
                              <textarea name="message" cols="35" rows="7" id="message"></textarea>
                              <br>
                              <input type="submit" name="Submit" value="send"></form>

 

and this is my php from DKs.. which I like.. because it does display the error.html if I leave a field blank.. but it will not pull the trigger and submit to me when I fill it all in... waaaa

 

<?php
if (empty($email) ||empty($name)||empty($phone)||!isset($phone)||!isset($name)||!isset($email))
{
  header( "Location: error.html" );
  exit;
}
else  if(!empty($name)||!empty($email)||!empty($phone)||isset($name)||isset($phone)||isset($email))
{

  //mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

  $admin = '[email protected]' ; 
  $name = stripslashes($_POST['name']) ;
  $message = stripslashes($_POST['message']) ;
  $email = stripslashes($_POST['email']) ;
  $phone = stripslashes($_POST['phone']) ;

  mail( $admin, "Feedback: $name", "Name: $name\nPhone: $phone\nEmail: $email\n\n$message", "From: $name <$email>" );


  $subject = 'Online Inquiry';
  $replymsg = 'Thank you for your email inquiry. One of our staff will respond shortly.' ; 
  mail( $email, $subject, $replymsg , "From: $admin" );

  header( "Location: thankyou.html" );
  exit;
}
?>

 

 

OK, I see an obvious mistake. You need to set $email, $name etc. at the beginning:

 

<?php

$name = stripslashes($_POST['name']) ;
$message = stripslashes($_POST['message']) ;
$email = stripslashes($_POST['email']) ;
$phone = stripslashes($_POST['phone']) ;

if (empty($email) ||empty($name)||empty($phone))
{
echo "Please Fill in the form!";

}
else if(!empty($name)||!empty($email)||!empty($phone)||isset($name)||isset($phone)||isset($email))
{

 //mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

 $admin = '[email protected]' ; 

 mail( $admin, "Feedback: $name", "Name: $name\nPhone: $phone\nEmail: $email\n\n$message", "From: $name <$email>" );


 $subject = 'Online Inquiry';
 $replymsg = 'Thank you for your email inquiry. One of our staff will respond shortly.' ; 
 mail( $email, $subject, $replymsg , "From: $admin" );
echo " Thank You for signing up!";
}
?>

 

Aww, ben, you beat me to it! :)

YAY.. thanks moon... I am so excited.. it worked. I put the html headers back in too..  thank you thank you thank you

 

now.. haha..  is there anything else I should consider..  security... email checking.. or is it ok as is?

 

Thank you all.

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.