Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Anything Goes
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:37

OT - E-Mail from form script?


Poster: tepidarium
Dated: Friday March 19 2004 - 19:38:20 GMT

Hi,
Does anyone know of a good script that will send to an e-mail address the results of a web form?

Thanks...


Poster: John
Dated: Friday March 19 2004 - 23:21:42 GMT

Formmail.


Poster: kevin3442
Dated: Friday March 19 2004 - 23:46:13 GMT

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


Poster: tepidarium
Dated: Saturday March 20 2004 - 0:13:55 GMT

thanks guys, I'm going to check this out...have a great weekend!

php formmail


Poster: waitman
Dated: Thursday May 13 2004 - 9:03:09 BST

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
Code:
<?php
$redirect = '/thankyou.html';
$recipient = 'addr1 __at__ freakinexample.com,addr2 __at__ freakinexample.com';

$e = __at__ 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]).'&nbsp;</td></tr>';
   }
}

$r = __at__ 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_\.]+ __at__ [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="'.urlencode($_POST['email']).'">'.htmlspecialchars($_POST['email']).'</a>';
$s = __at__ 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])."&nbsp;</td></tr>";
      }
   }
}
$message .= '<tr><td colspan="2">&nbsp;</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 __at__ freakinexample.com>\r\n";

mail ($recipient,$_POST['subject'],$message,$headers);

Header('Location: '.$redirect);
exit();
?>



2. form.html (simple example)
Code:
<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>