crosscheck
Regular Member
- Aug 12, 2010
- 424
- 231
I am looking for a script that will send a email when a button is clicked or after a form is submited
<?php
if($_POST['submit'])
mail('YOURMAIL', 'Someone Sent You Their Email!', "Someone sent you this email: " . $_POST['email']);
?>
<html>
<body>
<form method=POST>
Your Email: <input type='text' name='email' />
<input type='submit' name='submit' value='Send My Email To crosscheck!' />
</form>
</body>
</html>
[COLOR=#000000] [COLOR=#0000bb]<?php
$to [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]$_POST['email'][/COLOR][COLOR=#007700];
[/COLOR][COLOR=#0000bb]$subject [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]'the subject'[/COLOR][COLOR=#007700];
[/COLOR][COLOR=#0000bb]$message [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]'hello'[/COLOR][COLOR=#007700];
[/COLOR][COLOR=#0000bb]$headers [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]'From: SiteName <[email protected]>' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#dd0000]"\r\n" [/COLOR][COLOR=#007700].
[/COLOR][COLOR=#dd0000]'Reply-To: SiteName <[email protected]>' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#dd0000]"\r\n" [/COLOR][COLOR=#007700].
[/COLOR][COLOR=#dd0000]'X-Mailer: PHP/' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]phpversion[/COLOR][COLOR=#007700]();
[/COLOR][COLOR=#0000bb]mail[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$to[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]$subject[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]$message[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]$headers[/COLOR][COLOR=#007700]);
[/COLOR][COLOR=#0000bb]?>[/COLOR] [/COLOR]
<?php
if(isset($_GET['email')):
file_put_contents("email_log.txt", $_GET['email'] . " Opened Your Email On " . date("D M j G:i:s T Y"));
else:
mail('somemail', 'LOOK AT THIS', "<img src='" . __FILE__ . "?email=" . base64_encode('somemail') . "' width=0 height=0>", 'MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n');
?>
function spam_scrubber($value) { // removes potentially malicious code from the email
$very_bad = array('to:', 'cc:', 'bcc:', 'content-type:', 'mime-version:', 'multipart-mixed:','content-transfer-encoding:');
foreach ($very_bad as $v) {
if (stripos($value, $v) !==false) return '';
}
$value = str_replace(array("\r","\n", "%0a", "�0d"), ' ', $value);
return trim($value);
} // End of spam_scrubber() function.
$scrubbed = array_map('spam_scrubber', $_POST);
$scrubbed['name'] // replace name with your form value
<fieldset>
<legend>Contact Form</legend>
<form action="submit.php" method="post" enctype="application/x-www-form-urlencoded">
<ul>
<li><label for="name">Your Name:</label><input type="text" name="name" size="25" maxlength="200" id="yourname" /><br /></li>
<li><label for="email">E-mail:</label><input type="text" name="email" size="25" maxlength="200" id="email" /><br /></li>
<li><label for="phone">Phone:</label><input type="text" name="phone" size="25" maxlength="200" id="phone" /><br/></li>
<li><label for="comments">Your enquiry:</label>
<textarea name="comments" rows="10" cols="40" id="comments"></textarea></li>
</ul>
<p><input type="submit" value="Submit!" /></p>
</form>
</fieldset>
<?php
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$phone = htmlspecialchars($_POST['phone']);
$comments = htmlspecialchars($_POST['comments']);
?>
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "PUT YOUR EMAIL HERE";
$email_subject = "PUT A SUBJECT HERE";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = htmlentities($_POST['name']); // required
$email = htmlentities($_POST['email']); // required
$phone = htmlentities($_POST['phone']); // not required
$comments = htmlentities($_POST['comments']); // required
$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
if(!eregi($email_exp,$email)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "^[a-z .'-]+$";
if(!eregi($string_exp,$yourname)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Telephone: ".clean_string($phone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<p>Thank you for contacting us, we will reply ASAP</p>
<p>Here is a copy of what you submitted to us:</p>
<ul>
<li>Your name is: <?php echo $_POST['name']; ?></li>
<li>Your e-mail: <?php echo $_POST['email']; ?></li>
<li>Your phone number: <?php echo $_POST['phone']; ?></li>
<li>Comments: <?php echo $_POST['comments']; ?></li>
</ul>
<?
}
?>