Hi,
Does anyone know of a good script that will send to an e-mail address the results of a web form?
Thanks...
OT - E-Mail from form script?
Yeah... I've used that one myself in previous incarnations of our website. It'll require that your webserver (or host) allows CGI. You can also use mailto as the form's action, using the visiotr's own email client to send the mail, but that doesn't give you control over the output, and various browsers put up different messages when you use mailto.
Kevin
Kevin
-
- Mega User
- Posts: 169
- Joined: Sun Oct 05, 2003 4:21 am
php formmail
i had a customer using a formmail perl script, this thing has had security issues in the past (however they have probably been resolved.)
so I replaced it with a php script i threw together, seems to work similar to formmail. i wanted to mimick the functionality of formmail without messing around changing his form html.
the HTML email sending part could be a bit better, but works for the most part.
1. mail.php
2. form.html (simple example)
so I replaced it with a php script i threw together, seems to work similar to formmail. i wanted to mimick the functionality of formmail without messing around changing his form html.
the HTML email sending part could be a bit better, but works for the most part.
1. mail.php
Code: Select all
<?php
$redirect = '/thankyou.html';
$recipient = 'addr1@freakinexample.com,addr2@freakinexample.com';
$e = @explode(',',trim($_POST['env_report']));
$env = '';
if (count($e)>0)
{
foreach ($e as $value)
{
if ($value=='REMOTE_HOST')
{
$_SERVER[$value]=gethostbyaddr($_SERVER[$value]);
}
$env .= '<tr><td valign="top">'.$value.'</td><td valign="top">'.htmlspecialchars($_SERVER[$value]).' </td></tr>';
}
}
$r = @explode(',',trim($_POST['required']));
$required = array();
$err='';
$emailreq = 0;
if (count($r)>0)
{
foreach ($r as $value)
{
if ($value=='email') $emailreq = 1;
if (strlen(trim($_POST[$value]))<1)
{
$err .= "You did not enter a value for ".$value.", which is required.<br>";
}
}
}
if ($emailreq==1)
{
if(!eregi("^[a-zA-Z0-9_\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $_POST['email']))
{
$err .= 'You did not enter a valid email address.<br>';
}
}
//check required fields
if (strlen($err)>0)
{
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Error - Required Fields Missing!</title>
<style type="text/css">
body { Font-Family: Georgia, Helvetica, Tahoma, Verdana, sans-serif; }
blockquote { color: Red; }
</style>
</head>
<body>
<h3>Error - Required Fields Missing!</h3>
<p>Please note the errors below and <a href="javascript:history.back(0);">Click Here</a> to return to the previous page.</p>
<blockquote>'.$err.'</blockquote>
<p>Thank You.</p>
</body>
</html>
';
exit();
}
$message = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Form Submission '.date('Y-m-d H:i:s').'</title>
<style type="text/css">
body { Font-Family: Georgia, Helvetica, Tahoma, Verdana, sans-serif; }
td { background-color: #eeeeee; border: 1px solid #cccccc; padding: 5px; }
</style>
</head>
<body>
<h3>Form Submission '.date('Y-m-d H:i:s').'</h3>
<table border="0" width="100%">';
$_POST['email'] = '<a href="mailto:'.urlencode($_POST['email']).'">'.htmlspecialchars($_POST['email']).'</a>';
$s = @explode(',',trim($_POST['sort']));
if (count($s)>0)
{
foreach ($s as $value)
{
if ($value != 'email')
{
$_POST[$value] = htmlspecialchars($_POST[$value]);
}
if ($_POST['print_blank_fields']=='0')
{
if (strlen(trim($_POST[$value]))>0)
{
$message .= '<tr><td valign="top">'.str_replace('_',' ',$value).'</td><td valign="top">'.str_replace("\n",'<br>',$_POST[$value])."</td></tr>";
}
} else {
$message .= '<tr><td valign="top">'.str_replace('_',' ',$value).'</td><td valign="top">'.str_replace("\n",'<br>',$_POST[$value])." </td></tr>";
}
}
}
$message .= '<tr><td colspan="2"> </td></tr>';
if (strlen($env)>0)
{
$message .= '<tr><td colspan="2"><strong>Environment Variables</strong></td></tr>'.$env;
}
$message .= '</table><p>Have a Great Day!<br><br><em>The Web Server</em></p></body></html>'."\r\n\r\n\r\n";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Web Server <web.server@freakinexample.com>\r\n";
mail ($recipient,$_POST['subject'],$message,$headers);
Header('Location: '.$redirect);
exit();
?>
2. form.html (simple example)
Code: Select all
<form method="post" action="mail.php">
<input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,REMOTE_USER,HTTP_USER_AGENT">
<input type="hidden" name="print_blank_fields" value="0">
<input type="hidden" name="subject" value="Web Site Contact">
<input type="hidden" name="required" value="realname,email">
<input type="hidden" name="sort" value="Company,Home_Office,realname,email,subject">
<input type="text" size="25" maxlength="25" name="realname">
<input type="text" size="25" maxlength="38" name="Company">
<input type="text" size="25" maxlength="38" name="email">
<input type="Radio" name="Home_Office" value="Home">
<input type="Radio" name="Home_Office" value="Home">
<input type="submit" name="submit" value="submit">
</form>
Waitman Gobble
http://emkdesign.com/
http://emkdesign.com/