Jump to content

Email Script I made not working? ..::SHOCK::..


derrick1123

Recommended Posts

How come this isn't working?

Well for one I made it so that might be why...but still.

 

<?
$step = $_POST['step'];

if($step==0 || $step==""){ 

echo "
<form action='index.php' method='post'>
<input type='hidden' value='1' name='step'>
Your Name: <input type='text' name='name' size=30><br>
<br>
Email Address: <input type='text' name='email' size=30><br>
<br>
Subject: <input type='text' name='subject' size=30><br>
<br>
Message<br>
<textarea cols=30 rows=6 name='message' wrapping='virtual'></textarea><br>
<br>
<input type='submit' value='Send!'>
</form>
";

}

if($step=="1"){

// EDITABLE AREA \\

$error_page = "error.htm"; // Url of the error (fail) page
$thx_page = "thankyou.htm"; // Url of the thank you (success) page
$form_url = "sendemail.htm"; // Url of the form you used before
$max_message_len = 9999; // Max length of message
$to = "derrick1123@mygrassisemo.com"; // Email address to send email to

// END EDITABLE AREA - do not edit below here! \\

$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

// Error Checking
$e = 0;

if($name=="" || $name == NULL || $name == 0 || strlen($name)<3){ $e++; }
if(strpos($email, "@")===false || strpos($email, ".")===false || strlen($email)<5){ $e++; }
if($subject=="" || $subject == NULL || $subject == 0 || strlen($subject)<2){ $e++; }
if(strlen($message)>$max_message_len || strlen($message)<5){ $e++; }

// Go for it
if($e>0){

 die( "<meta http-equiv='REFRESH' content='0;url=$error_page'>" );

} else {

$message = nl2br($message);
$message = "<font face='verdana' size=4>Message from: $form_url: $name <$email>
<hr>
$message
<hr>
</font>";

mail($to, $subject, $message, "From: $name <$email>\r\nX-Mailer: $form_url \r\nContent-type: text/html; charset=UTF-8" );

echo "<meta http-equiv='REFRESH' content='0;url=$thx_page'>";

}
}
?>

 

BTW, this is the whole thing...there are no other pages.

Link to comment
Share on other sites

Try finding out where the error is coming from by doing this...

 

 


$error = "";
$e = 0;

if($name=="" || $name == NULL || $name == 0 || strlen($name)<3){ $error = "Name\n"; $e++; }
if(strpos($email, "@")===false || strpos($email, ".")===false || strlen($email)<5){ $error .= "Email\n"; $e++; }
if($subject=="" || $subject == NULL || $subject == 0 || strlen($subject)<2){ $error .= "Subject\n"; $e++; }
if(strlen($message)>$max_message_len || strlen($message)<5){ $error .= "Message\n"; $e++; }

// Go for it
if($e>0){

 echo "<b>Error Message:</b>".$error;
 exit();
 //die( "<meta http-equiv='REFRESH' content='0;url=$error_page'>" );

}

 

Try that change just to see where the error is occurring and then trace back from there.  A simple echo to the screen can save you lots of work.

Link to comment
Share on other sites

Ok.  To me then that means that there seems to be something happening improperly to both the "$name" as well as the "$subject" variables.  Lets do a little more trouble shooting...

 

Add a few lines in the middle here....

 

// Go for it
if($e>0){

 echo "<b>Name Value:</b>--".$name."--<br />\n";
 echo "<b>Email Value:</b>--".$email."--<br />\n";
 echo "<b>Subject Value:</b>--".$subject."--<br />\n";
 echo "<b>Message Value:</b>--".$message."--<br /><br />\n";

 echo "<b>Error Message:</b>".$error;
 exit();
 //die( "<meta http-equiv='REFRESH' content='0;url=$error_page'>" );

}

 

Always try echoing items to the page while you are testing.  That way you can see exactly what the value of a variable contains at any given time.  Note that I put the "--" before and after echoing the variables.  That way if you see "--0--" that means the variable contains the value of zero.  But if you see this "----" you will see that the variable (for whatever the reason) is completely empty.

 

Try it out and let me know.

Link to comment
Share on other sites

Ok.  So it definitely has the proper values.  Let's focus now on WHY it's generating the error.  It is triggering something in here...

"if($name=="" || $name == NULL || $name == 0 || strlen($name)<3)"

 

And in here...

"if($subject=="" || $subject == NULL || $subject == 0 || strlen($subject)<2)"

 

I'm guess it has something to do with either the word NULL or the value of zero (which is what I'm guessing the error is).  I'm willing to bet that it has something to do with the way that php handles if comparisons between strings and integers which is effectively what you are doing here.  Try running this code right AFTER where you added all of those lines echoing the values to the screen...

 

$name_test = "";

if($name=="")
{$name_test .= "Empty test <br />\n";}

if($name == NULL)
{$name_test .= "Null test <br />\n";}

if($name == 0)
{$name_test .= "Zero test <br />\n";}

if(strlen($name)<3)
{$name_test .= "String Length test <br />\n";}

echo "Name error is coming from: ".$name_test;

 

I hope you are learning something from all of this.  This is just a different way to troubleshoot things.  If you ever think there is an error in your code you can simply echo to the screen to see what is "really" going on.

 

Run this stuff and then let me know what your next step is gonna be.

Link to comment
Share on other sites

Thank you for helping me, but here are my errors:

Name error is coming from: Zero test
Subject error is coming from: Zero test

Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry. in C:\xampp\htdocs\email\index.php on line 98

I think I know why the SMTP isn't working...

Link to comment
Share on other sites

Thank you for helping me, but here are my errors:

Name error is coming from: Zero test
Subject error is coming from: Zero test

Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry. in C:\xampp\htdocs\email\index.php on line 98

I think I know why the SMTP isn't working...

----

Ok I guess I don't know >.<

Link to comment
Share on other sites

Ok so the error definetely has to do with the way that php handles if comparisons between integers (in this case 0) and strings.

 

So you need to take these lines...

if($name=="" || $name == NULL || $name == 0 || strlen($name)<3)
if($subject=="" || $subject == NULL || $subject == 0 || strlen($subject)<2)

 

And change them to this...

if($name=="" || $name == NULL || strlen($name)<3)
if($subject=="" || $subject == NULL || strlen($subject)<2)

 

Try that out and then post your findings back on here.

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.