Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Sending form info using PHP
Closed Thread
Old 01-09-2007, 04:30 PM   #1 (permalink)
 
Newb Techie

Join Date: Sep 2006

Posts: 27

bukwus is on a distinguished road

Default Sending form info using PHP

Hello
I'm trying to learn how to send form information to an email address. I can't use the basic mailto method because it's not reliable or secure. I can build the form in HTML and process the info with PHP, I'm just stuck at the 'sending the info' stage. I've done some research online and the CGI tutorials I've looked into are a bit over my head.
Can anyone help me out or point me to a resource (book, online, etc.) that can help me understand, at a basic level, the CGI involved with sending form information via email?
Thanks
bukwus is offline  
Old 01-09-2007, 09:55 PM   #2 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,410

office politics will become famous soon enough

Default

http://email.about.com/cs/phpemailtips/qt/et031202.htm - send email using php

you'll want to add info from the global POST array to populate data form the form fields

http://www.php.net/manual/en/reserved.variables.php

you should run validation on the input data to prevent injection attacks. also, beware of the script being able to send multiple times (by pressing f5)
office politics is offline  
Old 01-10-2007, 10:27 AM   #3 (permalink)
 
Newb Techie

Join Date: Sep 2006

Posts: 27

bukwus is on a distinguished road

Default

Thnaks for the reply.
So I can use the code provided at these links such that, when a user fills out a form on my site and clicks submit, the processed form information will be sent to whatever email address I designate as 'to'?
bukwus is offline  
Old 01-25-2007, 06:55 PM   #4 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
Default

As long as you have a mail server running (that your PHP configuration knows about), it should work dandy. A short example might be:
PHP Code:
<?php
// You would post to this page

$myEmail "jon@doe.com"// the address you want it sent to

$name $_POST['name']; // where "name" is the name of the field
$subject$_POST['subject'];
$message$_POST['message'];

$emailContents "$name

$message"
;

if (
mail($myEmail$subject$emailContents))
    echo 
"The form was submitted.";
else
    echo 
"There was a problem...call the nearest doctor!!";
?>
...and you'd use this by posting to the page with this code...if you included this on the page itself (with the form), you'd want to make sure you're receiving a post:
PHP Code:
if ($_SERVER['REQUEST_METHOD'] == "POST") {
// email the info
} else {
// show the form


Also, if you want to get advanced with it,
http://phpmailer.sourceforge.net/
is a full-featured awesome PHP mailer class.


...I really need to check for PHP questions more often... just over two weeks old! Sorry if I said more/less then what you wanted to hear, just let me know.
__________________
Vormund is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On