PDA

View Full Version : Beginner Help



QuizToon
03-23-2006, 09:30 PM
:( :confused: I am wanting to learn php and have done a very small piece of script and html which I have read in a book.

Problem is that it goes through the process and I get to see the thankyou page, but I dont receive any email.

Please can you tell what is wrong so that I can understand what i did wrong.

My server is able to use php.

Thanks in advance :)


html page code >
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Email</title>
</head>

<body>
<form method="post" action="sendmail.php">
Email: <input name="email" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>
</body>

</html>

php page code >

<?
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

mail( "graham.peach@ntlworld.com", "Feedback Form Results",
$message, "From: $email" );
header( "Location: thank_you.html" );
?>

Twey
03-23-2006, 09:36 PM
For a start, you need to terminate the extra headers with \r\n\r\n (double CRLF). Secondly, you need to check that your mail section is set up correctly in php.ini. This involves specifying a path for sendmail on *n?x, or an external SMTP server and address on Windows.

QuizToon
03-23-2006, 09:55 PM
Sorry I dont understand

I thought that when php is on the server thats it. wouldnt php.ini be on the server?

Twey
03-23-2006, 10:07 PM
Yes. Under *n?x it'll be in /etc, /etc/php, or other similar locations depending on your distribution.

QuizToon
03-23-2006, 10:50 PM
ok thanks

I have read a faq on my site and it says that all the php scripts should end in .php which it does

and i should add this line of code

ini_set("sendmail_from", " email@mydomain ");

although it doesnt say where it should go

Any ideas?

djr33
03-24-2006, 08:08 AM
Well... the main problem I see above is that you should make the variables work... they're just part of the quotes now.

look:
"From: $email" --> From: $email
"From: ".$email --> From: some@one.com

this may not be the only problem, but it'll help you.

If you don't get the above, then here....
basically, you can continue a thing that's in quotes after ending the quote by putting a dot.
Like this:

$var = "something".$othervar."somethingelse"."andmore".$var3.$var4;

That'll help you out a lot and let you do more complex syntax later on.

Twey
03-24-2006, 09:49 AM
Wrong, I'm afraid. In PHP, variables inside double quotes are parsed.
$hello = "Hi";
echo('$hello'); // $hello
echo("$hello"); // Hi
QuizToon: There are many other directives to set than just sendmail_from. I suggest you actually use the INI file (which contains explanatory comments) rather than ini_set().

djr33
03-25-2006, 11:16 AM
Dang. I had it backwards. My bad.

But... still... take note of that syntax for other stuff... it might be helpful.

thanks for catching that twey.