Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not submitting properly, can't see error

Status
Not open for further replies.

DaRNCaT

Technical User
Dec 18, 2002
566
NZ
I've got a form to email problem,
I've used this script before, and it's worked fine, only I've added in three drop select boxes, I don't know if this is what is causing the problem or not, any enlightenment on why it will not send the email would be great (It goes to the failed send deliverymessage)

I am running it from a different server from usual, but as it does form to email already with no problems, I couldn't figure out why it would spit the dummy over this.

Code:
<?php
//check if the form has been submitted
if (!isset($_POST[$Submit])) {
show_form($name, $email, $comments, $errormessage);
}
else if (isset($_POST[$Submit])) {
//if it has do the email processing
//trim trailing whitespace
$name=trim($name);
$email=trim($email);
$comments=trim($comments);
//do error checking

if (!eregi("^[a-zA-Z0-9_\-\.\-\\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email))
{

$errormessage = "<b><font color=\"red\"> The email field is empty or invalid. </font></b>";
show_form($name, $email, $comments, $errormessage);
	//echo "You have entered an invalid email address. Please return to the previous page and try again.";
	exit;
	}
	//set headers for the email to display and format email content
$headers .= "From: Domain: Webmaster Query <name@domain.com>\n";
$headers .= "Reply-To: ".$email."\n";
$headers .= "X-Sender: <name@domain.com>\n";
$headers .= "X-Mailer: PHP4\n";
$headers .= "X-Priority: 3\n";
$headers .= "Return-Path: <name@domain.com>\n";
$toaddress = "name@domain.com";
$mailcontent = "Customers Name: ".$name."\r\n"
				."Customers Email: ".$email."\r\n"
				."Customers Browser Type: ".$browsertype."\r\n"
				."Customers Operating System: ".$os."\r\n"
				."Customers Query Type: ".$querytype."\r\n"
				."Customers Comments: ".$comments."\r\n"
				."Contact Customer to follow up: ".$yes."\r\n";
				
		
//check if the email sends ok				
if(mail($toaddress,"Comments from ".$name,stripslashes($mailcontent),$headers) == true) {
  $deliverymessage = "<b>Thank you, your feedback has been sent.</b>";
  no_form($deliverymessage);
  }
else {

//if it doesn't spit out error message
  $deliverymessage = "<b>There has been a server error with your request.</b> Please press the back button on your browser and try again.";
  no_form($deliverymessage);
} 
}//end of isset submit
?>

The form is a pretty basic thing, and it error checks ok, so it's not broken up to that point.
Do I need to be defining an array with the select boxes - could this be my problem?
At the moment they are just like this (inside a print command- hence backslashes)

Code:
<td>Type of browser:</td>
    <td>      <label>
      <select name=\"browsertype\" id=\"browsertype\">
      <option selected>Choose your browser</option>
      <option value=\"IE\">Internet Explorer</option>
      <option value=\"Firefox\">FireFox</option>
      <option value=\"Opera\">Opera</option>
      <option value=\"Mozilla\">Mozilla</option>
      <option value=\"Other\">Other</option>
      </select>
      </label>
    </td>

I keep wondering if they should be name=\"browsertype[]\"
and then use an implode to put them into the email.

Thanks.


----------------------------------------
Sometimes, when my code just won't behave, I take it outside and make it listen to britney spears music, and when it comes back it's really well behaved. I wonder if it's suffering from post tramatic stress syndrome now..
 
A few comments and questions off the top of my head.

It looks like you're assuming that register_globals is turned ON, which is not the default for recent versions of PHP.

You have
Code:
if (!isset($_POST[$Submit]))
Where is the variable "$Submit" coming from?

Or do you really want to say:
Code:
if (!isset($_POST['Submit']))
Which checks whether a button named "Submit" has been pressed.
There is a difference, unless the variable $Submit has been set to the string "Submit".

Ken
 
It's a self calling page, and checks if there is a 'submit' before it does anything, currently the submit button looks like
Code:
<input type=\"Submit\" value=\"Submit\" name=\"Submit\">

I've had problems with form buttons before, but usually when the name and value are the same they are ok, I would assume that the page wouldn't show anything if this was a problem, as the entire page is printed within a function. show_form or no_form if the submit button has been pressed

----------------------------------------
Sometimes, when my code just won't behave, I take it outside and make it listen to britney spears music, and when it comes back it's really well behaved. I wonder if it's suffering from post tramatic stress syndrome now..
 
Then your check should be
Code:
if (isset($_POST['Submit']))
//
// or
//
if (!isset($_POST['Submit']))
The above code will always work, your method will work only when register_globals is turned ON, which usually isn't the case anymore, and when the name and the value are the same. If they are different, your code would fail.

Ken
 
I've tried both methods, it makes absolutly no difference to the result, it still won't send the mail, and I get the deliverymessage for not sent mail.

Is there a way to echo out the problem so I can fix it? I know how to show mysql errors, but I'm unsure on PHP ones.

----------------------------------------
Sometimes, when my code just won't behave, I take it outside and make it listen to britney spears music, and when it comes back it's really well behaved. I wonder if it's suffering from post tramatic stress syndrome now..
 
you can echo out foo and bar, in different parts of your script..

I have some comments:
Code:
if (!isset($_POST[$Submit])) {
show_form($name, $email, $comments, $errormessage);
}
else if (isset($_POST[$Submit])) {

You only need else there, theres no need for else if.

Code:
if(mail($toaddress,"Comments from ".$name,stripslashes($mailcontent),$headers) == true)

You dont need == true there..

Code:
if(mail($toaddress,"Comments from ".$name,stripslashes($mailcontent),$headers))

ps. are you sure you can send email with this server?
try to make a new php file with only mail() and check if it works..

when you check if mail() was sent, it only checks if the mail gets in the "Outbox" of the server. It does not check if the mail gets sent to the recipient

Olav Alexander Mjelde
Admin & Webmaster
 
I'm surprised you are not getting an error here:

Code:
$headers .= "From: Domain: Webmaster Query <name@domain.com>\n";

Maybe you are but the error reporting is off.

Try substituting this for the above:

Code:
$headers = "From: Domain: Webmaster Query <name@domain.com>\n";

Normally it would produce an error, "Undefined variable: header".

Because the variable must exist and have a value before ".=" can be used.

Thanks,
--Mark
 
Found out the problem, the server won't allow headers to be sent, so I've contacted the admin about it, it works fine without any headers, go figure (and yes I tried with and without the first .)

also
You only need else there, theres no need for else if.

not true, when it is only an else, it gives a parse error.

Thanks for all your help, hopefully admin can shed some light on why the headers aren't being allowed.


----------------------------------------
Sometimes, when my code just won't behave, I take it outside and make it listen to britney spears music, and when it comes back it's really well behaved. I wonder if it's suffering from post tramatic stress syndrome now..
 
What did code gave you a parse error when you used else instead of else if?

This should have worked fine:
Code:
if (!isset($_POST[$Submit]))
    show_form($name, $email, $comments, $errormessage);
else {
//
//
}

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top