PHP Email Form

They have: 161 posts

Joined: Jan 2005

Hello,

I am in need of assistance with some PHP coding. I'm not even a beginner, so please don't expect me to know ANYTHING. Sticking out tongue

Anyway, since HTML doesn't work for this, I am wondering how to create a form via PHP that emails the results to me. Smiling

I just want to be able to easily make text fields and text boxes, have the results emailed to a specific address, and the user taken to a success page.

Is it really so hard to ask? Sad Laugh

He has: 12 posts

Joined: Apr 2005

Clicky clicky!

That's a good one. If you get stuck just ask me.

They have: 161 posts

Joined: Jan 2005

:eek:

Thanks for the link!!! Smiling

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Another one that I use is PHPFormMail (http://www.boaddrink.com/) which started as a PHP version of the FormMail.pl program of yester-language...

Very simple to set up, you place the PHP file somewhere on your serer, adjust a few variables in there (very easy with the docs) and you are set to go.

You can then use it with mutlitple forms all over your site. In the form you set HIDDEN fields to command it. Note though, that people will be able to get your e-mail address from viewing your page source code.

A work around to this that I have used, is in the actual PHP file, at the beginning right below all the comments, add $_POST['recipient']="[email protected]"; to hard code in your e-mail address, then you don't have to include it on your form.

-Greg

They have: 161 posts

Joined: Jan 2005

Would any of you be kind enough to tell me/give me the code to make an upload form? Smiling PHP only please...I want to incorporate it into a form. Laughing out loud

Awaiting your replies...Thanks! Laughing out loud

timjpriebe's picture

He has: 2,667 posts

Joined: Dec 2004

I've never done that in PHP, myself, but this looks like a good tutorial:

http://www.netspade.com/articles/php/uploading.xml

Plus they use the word "smattering." Laughing out loud

They have: 161 posts

Joined: Jan 2005

This is getting me frustrated!
My email form won't work. Please help. Sad
http://www.easysig.info/contact.php

Contact.php File:

<?php
$ipi
= getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>

Use this form to contact EasySig, or to request EasySig's support of an email provider.
Contact Type:
General Contact
Email Provider Submission

Name:

Email:

Comments: Comments, Suggestions, Cries for Help

[?] Upload @yoursite.com: Please Click Here To Upload

Please rate EasySig if you have the time: Excellent Good Average Bad

Contacted.php File:
Thanks, your message has been sent.

<?php
$myemail
= "[email protected]";

if((!
$visitormail == "") && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo
"<h2>Use Back - Enter valid e-mail</h2>\n";
$tellem = "<h2>Feedback was NOT submitted</h2>\n";
}

if(empty(
$Name) || empty($Email) || empty($Comments)) {
echo
"<h2>Use Back - fill in all fields</h2>\n";
}

echo
$tellem;

if (
$emailvalidation == "y") {
$req1 = "Email format Validation \n" ;
}

if (
$fieldvalidation == "y") {
$req2 = "Required Form Field Validation \n";
}
if (
$htmlcontrol == "y") {
$req3 = "More intergratd HTML (in form) \n";
}
if (
$phpform == "y") {
$req4 = "Improved PHP form script generator \n";
}
if (
$htmlform == "y") {
$req5 = "A complete HTML form generator \n";
}
$req = $req1 . $req2 . $req3 . $req4 . $req5;

$todayis = date("l, F j, Y, g:i a") ;

$attn = $Name;
$subject = $attn;

$feedback = stripcslashes($Comments);

$message = " $todayis [EST] \n
Attention:
$attn (Rating:$rating) \n
From:
$Name ($Email)\n
Requested:
$req \n
Feedback:
$Comments \n
Additional Info : IP =
$ip \n
Browser =
$httpagent \n
Referral =
$httpref
"
;

$from = "From: $Email\r\n";

if (
$myemail != "[email protected]")
mail($myemail, $subject, $message, $from);

$screenout = str_replace("\n", "<br/>", $message);
?>

<?php
echo $screenout
?>

Try to test this out at http://www.easysig.info/contact.php ... as you can see it doesn't work! Sad

HELP!

They have: 161 posts

Joined: Jan 2005

Help.

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

If no one can help you before then, I'll be able to look at it tomorrow or monday morning.

-Greg

They have: 161 posts

Joined: Jan 2005

I feel so...neglected. Cry

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

Page doesn't load. I tried yesterday and figured it was a random error. Still nothing. Sad

They have: 5,633 posts

Joined: Jan 1970

Dont take it personally. The people on this fourm are only helpfull 3 of 5 posts. I cannot help because I try to avoid php. I'll write you a asp or asp.net script though.

He has: 388 posts

Joined: Apr 2005

Put this in a file called mail.php
and remember to changethe $to variable to show your email

  <!-- you can insert all the html you want around the php -->
  <?
  $name=$_POST['name'];
  $email=$_POST['email'];
  $comments=$_POST['comments'];
  $to="your e-mail here";
  $subject="comments from your website";
$message="$name just sent you an email from the form on your website. They said:\n$comments\n\nTheir e-mail address was: $email";
  if(mail($to," $subject",$message,"From: $email\n ")) {
  echo "Thank you $name for your comments.";
  } else {
  echo "There was a problem sending the comments.<br> Please check that you filled in the form correctly.";
  }
  ?>
  <!-- you can put html here too -->
 
'

and then this is the form for you to put anywhere you want

 
  <form action="mail.php" method="post">
  Your Name: <input type="text" name="name">
  your E-mail: <input type="text" name = "email"><br>
  Comments<br>
  <textarea name="comments"></textarea><br><br>
  <input type="submit" value="Send">
  </form>
 
'

If you have any questions on adapting this script. please post them here I and im sure evreyone else will be glad to help.

They have: 161 posts

Joined: Jan 2005

Ok I went with vibin's method, but it's still not working. Here is the code for each page:

mail.php

<?
$name=$_POST['name'];
$email=$_POST['email'];
$comments=$_POST['comments'];
$rating=$_POST['rating'];
$to="[email protected]";
$subject="EasySig Contact Form";
$message="$name just sent you an email from the form on your website. They said:\n$comments\n\nTheir e-mail address was: $email"/n/n$name has rated EasySig with "$rating";
if(mail($to," $subject",$message,"From: $email\n ")) {
echo "Thank you $name for your comments.";
} else {
echo "There was a problem sending the comments. Please check that you filled in the form correctly.";
}
?>

contact.php
Use this form to contact EasySig, or to request the support of an email provider.

Name:

Email:

Comments:

Please rate EasySig if you have the time: Excellent Good Average Bad

[?] Upload @yoursite.com: Please Click Here To Upload

He has: 388 posts

Joined: Apr 2005

take the quotes from around $rating in the $message variable.

They have: 161 posts

Joined: Jan 2005

Hi, it still doesn't work.

Here is the file coding again:

<?
$name=$_POST['name'];
$email=$_POST['email'];
$comments=$_POST['comments'];
$rating=$_POST['rating'];
$to="[email protected]";
$subject="EasySig Contact Form";
$message="$name just sent you an email from the form on your website. They said:\n$comments\n\nTheir e-mail address was: $email"/n/n$name has rated EasySig with a rating of $rating;
if(mail($to," $subject",$message,"From: $email\n ")) {
echo "Thank you $name for your comments.";
} else {
echo "There was a problem sending the comments. Please check that you filled in the form correctly.";
}
?>

After an $email variable, there's a " mark for some reason. Please help me.. Sad

I don't know what the problem is..

He has: 388 posts

Joined: Apr 2005

ok i fixed it and tested it is should now work

here it is:

<?
$name=$_POST['name'];
$email=$_POST['email'];
$comments=$_POST['comments'];
$rating=$_POST['rating'];
$to="[email protected]";
$subject="EasySig Contact Form";
$message="$name just sent you an email from the form on your website. They said:\n$comments\n\nTheir e-mail address was: $email $name\n has rated EasySig with a rating of $rating";
if(mail($to," $subject",$message,"From: $email\n ")) {
echo "Thank you $name for your comments.";
} else {
echo "There was a problem sending the comments. Please check that you filled in the form correctly.";
}
?>

They have: 161 posts

Joined: Jan 2005

Still does not work. Cry

He has: 388 posts

Joined: Apr 2005

what does it say when you try it

They have: 161 posts

Joined: Jan 2005

You go ahead and try it out yourself at http://www.easysig.info/contact.php

For some reason, once you submit it...you are redirected to the main page (index.php). -.-

H-E-L-P.

He has: 388 posts

Joined: Apr 2005

The action of your form is index.php thats why its ment to be mail.php

They have: 161 posts

Joined: Jan 2005

...it is post mail.php command.

He has: 388 posts

Joined: Apr 2005

sorry i was lookin at the wrong form.
I have absolutely no idia why that is happening

He has: 388 posts

Joined: Apr 2005

try putting the php below the form and using

<?php
echo $_SERVER['PHP_SELF'];
?>
as the action

They have: 161 posts

Joined: Jan 2005

Alright..I'm about to slap somebody.

Someone: Please HELP me! Cry

chrishirst's picture

He has: 379 posts

Joined: Apr 2005

you have two tags and only one the first has action="index.php"> that will be the one that takes precedence.

They have: 161 posts

Joined: Jan 2005

chrishirst wrote: you have two tags and only one the first has action="index.php"> that will be the one that takes precedence.

Success! Smiling

Thank you everyone! Laughing out loud

He has: 388 posts

Joined: Apr 2005

wow it was that simple i didn't notice it well done chrishirst

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.