Email Forms?

WhiteOut

New Member
Messages
111
Reaction score
0
Points
0
How can I add a form that will email me the information typed in the boxes to my site? I tried using Coffeecup Web Form Builder, but it doesnt seem to be working. I dont recieve the email. Also, Im sorry if this is the wrong section for this. I wasnt sure where to put it.
 

Sup3rkirby

New Member
Messages
181
Reaction score
0
Points
0
Ehh, I would assume you are in the right place as this is about help for your site.

Well you can easily do this with a form(of course) and a little PHP magic.

PHP:
<?PHP
 
// SET VARIABLES / THE INFORMATION THE FORM POSTED
$to = "name@domain.com";
$from = $_POST['email'];
$subject = "EMAIL SUBJECT HERE";
$name = $_POST['name'];
$message = $_POST['message'];
$headers .= "From: {$from}" . "\r\n";
$headers .= "Reply-To: {$from}" . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();

// CHECK WHETHER ANY OF THE FIELDS ARE EMPTY. NOTE: || means OR
if ($from == "" || $name == "" || $message == "")
{
  // CHECK IF EMAIL FOLLOWS PATTERN: NAME@DOMAIN.COM/CO.UK/ORG.NET ETC
  if (ereg("[[:alnum:]]+@[[:alnum:]]+\.[[:alnum:]]+", $from))
  {
    // IF ANY OF THE FIELDS ARE EMPTY SHOW THIS MESSAGE.
    echo "<font color=red><center>Not all required fields were filled in!";
  } else {
    echo "<font color=red><center>You MUST enter a valid email address!";
  }
} else {
 
  // CREATE THE BODY OF THE MESSAGE

  $body .= "Subject: {$subject}\n";
  $body .= "From: {$from}\n";
  $body .= "Message: \n{$message}\n";

  // SEND THE MAIL
  mail($to, $subject, $body, $headers);

  echo "<font color=red><center>Mail Sent!</center></font>";
}

?>

And then all you need is a form that has 3 fields(at least these three): name, email, message

Those three exactly(lower case and all), since this is what the PHP will look for. That script can be customized a bit and you can do that yourself(if you know how) or you can ask for help.

Please Note: that PHP script will simply display a message that either sends the script or reports an error. To redirect the page back to your site(like a 'success' page), add this line right after the 'Mail Sent!' line:
PHP:
  echo "<meta HTTP-EQUIV='REFRESH' content='0; url=http://www.yoursite.com/'>";
 

WhiteOut

New Member
Messages
111
Reaction score
0
Points
0
I get a message saying Warning: mail() has been disabled for security reasons. What do I do?
 
Top