FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Please help with php-quick question





photographerguy
I tried to read a few basic tutorials on php. Past an echo 'Hello World', I am lost. I am trying to get a form to email to work. I was using cgiemail to do this on another host. I was told it would probably be easier to use php because it is already installed.

I have a form with name, email, phone number, and comments fields.
I am under the impression that I can create a simple text file to get these field inputs emailed to my address.

If a create a file called whatever.php and put it in my root directory, is that it? I think I must have the action on my submit button be "whatever.php" with the post method. Is this correct?

Can someone please show me how to do this? I am under the impression that this is a small file (5-10 lines of code)?
Stubru Freak
Code:
$message = "Name: " . $_POST["name"] . "\n"
                 . "Email: " . $_POST["email"] . "\n"
                 . "Phone: " . $_POST["phone number"] . "\n"
                 . "Comments: " . $_POST["comments"] . "\n";
mail("your_email@address", "Form Input", $message);


Post the data to this file like you said.
photographerguy
Thank you for the script.

on my submit button I have:

on (release) {
getURL("http://www.digitalglassdesign.com/formail.php", "_self", "POST");


the file formail.php in my root is:

$message = "Name: " . $_POST["name"] . "\n"
. "Phone: " . $_POST["phone"] . "\n"
. "Email: " . $_POST["email"] . "\n"
. "Subject: " . $_POST["subject"] . "\n"
. "Comments: " . $_POST["message"] . "\n";
mail("info@digitalglassdesign.com", "Form Input", $message);

When I test the form I get a white page that says:

$message = "Name: " . $_POST["name"] . "\n" . "Phone: " . $_POST["phone"] . "\n" . "Email: " . $_POST["email"] . "\n" . "Subject: " . $_POST["subject"] . "\n" . "Comments: " . $_POST["message"] . "\n"; mail("info@digitalglassdesign.com", "Form Input", $message);

It doesn't work.
Is there something I am doing wrong?
Slammer
make sure you have the php tags around your script.

You must start it with at

<?php

and end with

?>

That should fix it i think. As long as there is php installed on the server.
photographerguy
it works. thank you so much.

i put the <?php and ?> at the start and end and it's good.

i get a blank white page when i hit submit, it doesn't seem to load all the way, is this normal? i guess as long as it works.

if i put an echo command at the end, could i say thank you after they submitted the form?
raver
photographerguy wrote:

if i put an echo command at the end, could i say thank you after they submitted the form?


sure you can, just remember to put some error checking. WHat it would be best is to separate your variables right at the start and put something like:

if(!$whatever)
{ echo "you didn`t fill out a field";
}
exit

whatever... i`ll help you out more later, haven`t slept all night studying for an exam and i`ll leave in half an hour to pass it.. hopefully
laterz Wink
Stubru Freak
Ow, sorry, forgot about the <?php ?> :p

You can put whatever after and before the <?php ?> and it will be treated as normal html. You could also echo it.
PatTheGreat42
I would suggest putting the mail function in an if statement. The advantage of this is that it allows you to alert the user if the message was sent. If the message was unsuccessful, the mail function returns false. Therefore, you could use a bit of code like this:

Code:
if(mail());
{
     echo "Mail sent successfully!";
}
else
{
     echo "The message did not get sent.  You might want to try it again.";
     include(mailform.php);
}


It keeps users from being upset when their email never gets a reply, ya know?
photographerguy
Thanks Pat

I can use all the help and suggestions I can get. I think that is a good idea.
Thanks to everyone who helped me get this working.
Related topics
simple php problem, please help...
Fix for deleting files/directories owned by apache
phpBB2 ERROR PLEASE HELP
please help me, i don't know anything here...
mysql base error please help
please help quick
please help i just need people to visit a page
A problem.. please help
THIS IS DRIVING ME INSANE!! PLEASE HELP!
search engine friendly links in phpBB3... please help
Can someone please help me with my website?
PHP MySQL Question
VERY URGENT! Please Help Me!
Please Help Me....
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.