Sending form info using PHP

Status
Not open for further replies.

bukwus

Baseband Member
Messages
53
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
 
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'?
 
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:
<?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:
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. :p
 
Status
Not open for further replies.
Back
Top Bottom