Forum Moderators: coopster

Message Too Old, No Replies

Configuring a simple email form....

         

Bubzeebub

9:04 pm on Sep 22, 2004 (gmt 0)

10+ Year Member



I am interested in creating a server side script so that a user can click on the 'Submit' button and be able to send me email without my email being shown. Does anyone know how to configure this or perhaps show an example of a working one I can follow? Any help would be appreciated.

Thanks,
Bub

crashomon

9:08 pm on Sep 22, 2004 (gmt 0)

10+ Year Member



Hello, you can search on the web and find any number of basic email scripts.

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]

kumarsena

9:11 pm on Sep 22, 2004 (gmt 0)

10+ Year Member



u mean like a web form that the visitor fill in or a way to link to ur email address without amking your email add public?

if it is the first ur trying to do the form method, then u wanto use the mail() function see [php.net...]

Bubzeebub

1:02 am on Sep 23, 2004 (gmt 0)

10+ Year Member



Thanks for your replies but I'm still a bit lost. The comments in the first reply said "just open up confirm.php ." Does this mean that I have to have some special file or software?

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).

Bubzeebub

3:26 am on Sep 23, 2004 (gmt 0)

10+ Year Member



Anyone out theeeeere?

Bubzeebub

3:34 am on Sep 23, 2004 (gmt 0)

10+ Year Member



CRASHOMON...do I just copy and paste that into my contact page? If so, then what part? I'm a total newbie...so assume I know nothing.

Timotheos

3:49 am on Sep 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Bubzeebub,

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