When you say "not working", what do you mean exactly?
Is nothing happening? Are you getting a blank page?
Or does it print "You must fill in all of the fields.", or "Sorry, there has been an error."?
Aside from the email being sent, what else is supposed to happen? Maybe you should input some more debugging code (more echoes, etc..). Is something happening that isn't supposed to be happening?
Perhaps some of those variables you're testing for don't exist? IE. $Name should actually be $_GET['Name'] or $_POST['Name'] or something...
Regardless, your post was quite vague and it's hard to troubleshoot what the problem is as it could be anything. Please fill in some blanks and hopefully we can help you resolve this issue.
Basically, when I try to submit the form (with or without data in the input fields) I just end up at a blank page. For in action: http://redblizzard.astahost.com/contact.php
Yes, I think it's got to do with accessing your variables ($Name versus $_GET['Name']).
Try this code instead:
PHP Code:
<?php
if(isset($_GET['submit'])) {
echo 'Submit is set!<br/>';
if (!empty($_GET['Name']) && !empty($_GET['Email']) && !empty($_GET['Subject']) && !empty($_GET['Message'])) {
echo 'Sending email!</br>';
mail("ollie.craig@virgin.net", "$_GET['Subject']", "$_GET['Message']", "From: $_GET['Name'] - $_GET['Email']") or die("Sorry, there has been an error.");
header("refresh: 0; url=contactdone.php");
}
else {
echo "You must fill in all of the fields.";
}
}
else {
echo 'Submit not set...<br/>';
}
?>
If that seems to work after your various testing you can remove the unnecessary echoes as you see fit.
Another area where you may or may not run into problems is in your php.ini file: you need to setup your SMTP server for the mail() function. If it's not set to a valid SMTP server, your mail() function won't send emails anywhere and may error out...
Edit:
You may or may not have noticed this (or known this), but I accessed your form elements through the $_GET array as the METHOD attribute of your form held GET as the value. Had it held POST, I would've used the $_POST array to access your form elements.
Hope that helps,
Sadiq.
Last edited by sad69; 11-22-2004 at 08:25 PM..
Reason: get/post edumacation..
MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
Another area where you may or may not run into problems is in your php.ini file: you need to setup your SMTP server for the mail() function. If it's not set to a valid SMTP server, your mail() function won't send emails anywhere and may error out...
I don't have access to the sever, so that might be a problem. However, I've used PHPFormGenerator, and the mail() function in the form worked then.
I got a parse error this time...
Quote:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/redblizz/public_html/contactprocess.php on line 7
I'll try with POST instead of GET, and see if that works.
I'm not sure if this is the problem (I never keep variables inside of double-quotes, I usually close the string and concatenate...).
One of the following 2 line 7's might work:
PHP Code:
mail("ollie.craig@virgin.net", "{$_GET['Subject']}", "{$_GET['Message']}", "From: {$_GET['Name']} - {$_GET['Email']}") or die("Sorry, there has been an error.");
or:
PHP Code:
mail("ollie.craig@virgin.net", $_GET['Subject'], $_GET['Message'], "From: ".$_GET['Name']." - ".$_GET['Email']) or die("Sorry, there has been an error.");
Here is my version of the code. It first checks to see if any of the variables you are sending are empty if not then it sends you the email. I have tested this script of mine and it works 100% without problems! I did notice that someone could easily flood you with emails by going to that url six or seven hundred times. I suggest you add a cookie that limits how many emails they could send per hour and maybe add some other protection.
Code:
<?php
error_reporting(0);
if(!empty($_GET['Name']) and !empty($_GET['Email']) and !empty($_GET['Subject']) and !empty($_GET['Message']))
{
mail("ollie.craig@virgin.net",$_GET['Subject'],$_GET['Message'],"From:<".$_GET['Name'].">".$_GET['Email']) or die("Mail() Failed.");
header("refresh: 0; url=contactdone.php");
}
else
{
die("You left a part of the form blank. Please hit your browsers back button and verify you have all parts of the form filled out.");
}
?>