[solved] Using PHP to send website feedback email

This is my first attempt to use PHP ever, just FYI! I am using some php code from here And every time I try to use the form, I get an error message:[code]The page cannot be found
The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.

Please try the following:

* Make sure that the Web site address displayed in the address bar of your browser is spelled and formatted correctly.
* If you reached this page by clicking a link, contact the Web site administrator to alert them that the link is incorrectly formatted.
* Click the Back button to try another link.

HTTP Error 404 - File or directory not found.
Internet Information Services (IIS)

Technical Information (for support personnel)

* Go to Microsoft Product Support Services and perform a title search for the words HTTP and 404.
* Open IIS Help, which is accessible in IIS Manager (inetmgr), and search for topics titled Web Site Setup, Common Administrative Tasks, and About Custom Error Messages.[/code]I've done quite a bit of searching today on this solution and played around in the account privileges and so forth but to no avail. Here is the exact code in my HTML file:[code]<link rel="stylesheet" type="text/css" href="iframe.css" media="screen"/>

MBD Tech-Support

2007-10-27 David
<p>Please fill out the form below to submit feedback.</p><BR>

<form action="mail.php">
<b>Name:</b><br />
<input type="text" name="nickname" value="Your Name" /><br /><br />
<b>E-mail:</b><br />
<input type="text" name="email" value="Your E-mail address" /><br /><br />
<b>Message:</b><br />
<textarea name="message" rows="5" cols="50"></textarea><br />
<input type="hidden" name="ip" value="<? echo $REMOTE_ADDR; ?>" />
<input name="Submit" type="submit" value="Submit" />
<input name="Submit" type="reset" value="Reset" />
</form>
[/code]I get the same result weather it's in the
or out. And this is the code in my [b]mail.php[/b] file:[code]$error = "There are some fields not filled in, click here to go back";

if($nickname == “” || $message == “” || $email == “”){
echo $error;
}

elseif($ip == “”){
echo “Sorry, an unknown error has occured”;
}

else{
$yourwebsite = “http://techsupport”;
$recipientname = “David”;
$subject=“Tech-Site feedback”;
$recipient="[email protected]"; // changed email for this post

$header = “From: $nickname <$email>rn”;
$header .= “MIME-Version: 1.0rn”;
$header .= “Content-Type: text/html; charset=iso-8859-1rn”;
$header .= “X-Priority: 3rn”;
$header .= “X-MSMail-Priority: Normalrn”;
$header .= "X-Mailer: PHP / ".phpversion().“rn”;

$content= "
Dear $recipientname, $nickname has sended you an e-mail from $yourwebsite.

Message:
$message


You can contact $nickname back at $email.";

mail($recipient, $content, $header);

echo “Thanks! Your e-mail has been sended succesfull $nickname. We will contact you back on $email ASAP”;
}[/code]Any help on this would be just awesome :D

this means that there is no mail.php in the same folder as the html-file.

plz doublecheck the name and location of the mail.php.

Here’s a screenshot of the root directory. All files are there that I can tell.

are u using a -tag?

or a location-header in the mail.php?

what URL is ur browser showing wile displaying that error?

the address it displays when displaying the error is:
http://techsupport/mail.php?nickname=Yo … mit=Submit

and about the & location-header, the exact code I’m using is in my First post. If you don’t see it, I don’t have it. I did a copy/paste from the source site. So if he was using something (or posted the code w/o testing) else than what he gave, that would be a bummer. =

it’s not a PHP error

just check ur server config and logs

and maybe doublecheck again if http://techsupport/ is realy pointing to T:.

btw: the code was ment to go inside a structure. u have to add the hole and part. thats why i thought u only pased a part of the code

Hmm, I’ll try adding the code to a structure and see how that turns out. As I am just displaying the contents of the files in an iframe, this may be my problem.

Hmm, nope, same result.
Also, my hello.php is not working either. I think this may be more of an IIS problem. shakes fist

[edit] Hmm, I got hello.php to work! However, when I use my mail.html file or any refrence to mail.php it bugs out. Once again, this is the exact code for my mail.php file:[code]$error = “There are some fields not filled in, click here to go back”;

if($nickname == “” || $message == “” || $email == “”){
echo $error;
}

elseif($ip == “”){
echo “Sorry, an unknown error has occured”;
}

else{
$yourwebsite = “http://techsupport”;
$recipientname = “David”;
$subject=“Tech-Site feedback”;
$recipient="[email protected]";

$header = “From: $nickname <$email>rn”;
$header .= “MIME-Version: 1.0rn”;
$header .= “Content-Type: text/html; charset=iso-8859-1rn”;
$header .= “X-Priority: 3rn”;
$header .= “X-MSMail-Priority: Normalrn”;
$header .= "X-Mailer: PHP / ".phpversion().“rn”;

$content= "
Dear $recipientname, $nickname has sended you an e-mail from $yourwebsite.

Message:
$message


You can contact $nickname back at $email.";

mail($recipient, $content, $header);

echo “Thanks! Your e-mail has been sended succesfull $nickname. We will contact you back on $email ASAP”;
}[/code]What’s missing from there?

as i said: the 404-error is not a php problem, its an IIS problem.

Thanks for the help so far :slight_smile:

TALK ABOUT FRUSTRATING!

I’ve been browsing the forums, and the PHP Manual for the last two days now to get this sucker going, and I’m stuck at this stupid point.

<?php $test = "test" echo "$test" ?>DOES NOT WORK

<?php echo "test" ?>DOES WORK and phpinfo() also works.

What the heck is the difference here? I have the ISAPI PHP filter enabled, .php is in the ISAPI extensions and the ANON user IIS installs DOES have full access to the PHP folders.

[edit] By does not work, I mean the page loads with just a plain white screen. When I go to view source, no data is shown.

syntax error.

missing ‘;’

has to be:
[php]<?php
$test = “test”;
echo “$test”;
?>[/php]

the last ‘;’ (the one in front of ?>) may be left away. thats why <?php echo "text" ?> works

enable error_reporting and display_errors in the php.ini

have u considered using Apache?

You were correct, I was missing the ; in the file. I didn’t realize that PHP was so picky about them. I also got the mail() working via my PHP.ini file [mail functions] area. Now, I’m running into even more problems. Heh.

I have enabled error reporting, and I’m getting some variable errors:Notice: Undefined variable: name in C:InetpubTechSupportcontentmail.php on line 3It doesn’t seem that my mailForm.php is passing data on to my mail.php file. I’ll post all the most recent code below.

mailForm.php[code]

<head>
    <title>MBD Tech-Support</title>
</head>

<body>

	<link rel="stylesheet" type="text/css" href="iframe.css" media="screen"/>
	
	<div class="content">
		<h1>MBD Tech-Support</h1>
		<div class="descr">2007-10-27 David</div>
	
		<p>Please fill out the form below to submit feedback.</p><BR>
		
		<form action="mail.php">
		<b>Name:</b><br />
		<input type="text" name="$name" value="Your Name" /><br /><br />
		<b>E-mail:</b><br />
		<input type="text" name="$email" value="Your E-mail address" /><br /><br />
		<b>Message:</b><br />
		<textarea name="$message" rows="5" cols="50"></textarea><br />
		<input name="Submit" type="submit" value="Submit" />
		<input name="Submit" type="reset" value="Reset" />
		</form>
	</div>

</body>
[/code]

mail.php[code]<?php
error_reporting(E_ALL);
if($name == “” || $message == “” || $email == “”){
echo “Some fields were left blank, you must fill in all fields before you can send a note.”;
}
else{
$yourwebsite = “http://techsupport”;
$recipientname = “David and Michael”;
$subject=“Tech Site Suggestion”;
$to="[email protected]";

$header = "From: $name <$email>rn";
$header .= "MIME-Version: 1.0rn";
$header .= "Content-Type: text/html; charset=iso-8859-1rn";
$header .= "X-Priority: 3rn";
$header .= "X-MSMail-Priority: Normalrn";
$header .= "X-Mailer: PHP / ".phpversion()."rn";

$content = "
Dear $recipientname, $name ($email) has sent you a note.
Message:
$message";

mail($to, $subject, $content);

echo "Thanks $name ($email)! Your e-mail has been sent succesfully. David or Michael will contact you back ASAP.";

}
?>[/code]

u have set error_repoting to E_ALL.

that makes it display notices.
notices are very good for debuging, as good coding style should include settin al variables, and missepelling, or using absolved variables can be traced.

BUT a notice i a minor thing not a real error.

about the ‘;’:
the ‘;’ is like a lineend in some othere programing languages. php has to be picky about that, as it dosn’t care at all about linefeeds. just imagine the ‘;’ beeing a linefeed and u get used to that very fast.

That’s good to know, thanks!

However, it’s spitting out an error even though no fields are blank. It’s claming that $name is not being set even though it is in mailForm.php. Am I missing a pass through function or something?

a unset vaiable can ony be checkt by isset($varibla).

it’s quite easy: if u try to check $variable (for true) it needst to access the content inside that varible. as there was never any content inserted into that variable (it was not set) it returns that error.
isset($variable) is checking if it had any content asigned (without trying to assess that content) and returns true/false on that.

hope this helps

Well, I’ve tried using is_null($var), isset($var), and if ($var == NULL) { and all are returning errors that the $var is not being set. Is the code in my mailForm.php correct to send the data to the mail.php file? Because it doesn’t seem any information is being sent between the two.

It looks like I got it! I put $name = $_GET[name]; $email = $_GET[email]; $message = $_GET[message]; in the beginning of the mail.php file and it’s now retaining data :D

notice: undifined constant …

its $_GET[‘name’] NOT $_GET[name]

$_GET[name] IS WRONG, but PHP is gractios.

It’s wrong? What’s the difference, or is it a security risk?

[edit] btw, I changed it to ‘var’ ;)

Sponsor our Newsletter | Privacy Policy | Terms of Service