Forum Moderators: coopster
Here's one from Matt Perconi that I got off of phpfreaks
enjoy!
Patrick Elward
<?php
/*set the following value below - $to = your email address.
everything else here you can leave as is, just open up confirm.php
and set the page you wish to direct people to after the mail has been sent
if you wish to change it to something other than index.php*/
$to = 'name@example.com'; //Address mail is to be sent to
$from = $_REQUEST['email']; //Sets the senders mail address
$subject = $_REQUEST['subject']; //Sets the subject from the mail form
$confirm = 'confirm.php'; //Sets the page to direct to if the mail is sent
$error = 'mailerror.php'; //Sets the page to direct to if the mail is unsent
// Don't touch anything else //
$mailheader = "From: $email\r\n";
$mailheader .= "Reply-To: $email\r\n";
if (isset($HTTP_POST_VARS)){
$mailbody = '';
while (list($key, $value) = each($HTTP_POST_VARS))
{
$mailbody .= $key . ' = ' . $value . "\r\n";
}
}
$mailforms = mail($to, $subject, $mailbody, $mailheader);
if($mailforms)
{
include("$confirm");
}
else
{
include("$error");
}
?>
[edited by: coopster at 9:23 pm (utc) on Sep. 22, 2004]
[edit reason] generalized email address [/edit]
if it is the first ur trying to do the form method, then u wanto use the mail() function see [php.net...]
I also checked php.net and it mentioned having access to sendmail. Is this something that I'd have to work with my web host on? I'm a bit new at this all so I need a little bit of hand holding and step by step instruction. I have the form already...just need to edit the source code (IF that's all I need).
Looks like you'll want to make another file called something like mail.php with the script above. Now have your form post to that file with the variables 'email', 'subject' and anything else you want like 'body'. Now set up another file called 'confirm.php' which will say something like "You're mail has been sent. Thank you soooo much." You'll also need a file 'mailerror.php' which displays "Whoops, we couldn't send your mail at this time."
Your host should all ready have the mail function setup. To confirm this you could always run the phpinfo() function and look at the mail directives.
Tim