Php 发送给发件人/提交人的自动回复电子邮件
我刚刚继承了一个PHP表单,我需要的是表单提交者收到他们刚刚在字段中输入的内容的收据。这就是我所拥有的,不知道从哪里开始。其他一切都很好,我在他们提交邮件时收到了邮件,我只需要他们收到一份Php 发送给发件人/提交人的自动回复电子邮件,php,Php,我刚刚继承了一个PHP表单,我需要的是表单提交者收到他们刚刚在字段中输入的内容的收据。这就是我所拥有的,不知道从哪里开始。其他一切都很好,我在他们提交邮件时收到了邮件,我只需要他们收到一份 <?php // OPTIONS - PLEASE CONFIGURE THESE BEFORE USE! $yourEmail = "email@email.com"; // the email address you wish to receive these mails through
<?php
// OPTIONS - PLEASE CONFIGURE THESE BEFORE USE!
$yourEmail = "email@email.com"; // the email address you wish to receive these mails through
$yourWebsite = "Application"; // the name of your website
$thanksPage = ''; // URL to 'thanks for sending mail' page; leave empty to keep message on the same page
$maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4
$requiredFields = "name,lastname,email,Phone,ReferredBy"; // names of the fields you'd like to be required as a minimum, separate each field with a comma
$textlink ='<a href="confirmation.html">Click Here And Take The Next Step</a>.' ;
// DO NOT EDIT BELOW HERE
$error_msg = array();
$result = null;
$requiredFields = explode(",", $requiredFields);
function clean($data) {
$data = trim(stripslashes(strip_tags($data)));
return $data;
}
function isBot() {
$bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot", "Teoma", "alexa", "froogle", "inktomi", "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory", "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot", "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz");
foreach ($bots as $bot)
if (stripos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
return true;
if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ")
return true;
return false;
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
if (isBot() !== false)
$error_msg[] = "No bots please! UA reported as: ".$_SERVER['HTTP_USER_AGENT'];
// lets check a few things - not enough to trigger an error on their own, but worth assigning a spam score..
// score quickly adds up therefore allowing genuine users with 'accidental' score through but cutting out real spam :)
$points = (int)0;
$badwords = array("javascript");
foreach ($badwords as $word)
if (
strpos(strtolower($_POST['comments']), $word) !== false ||
strpos(strtolower($_POST['name']), $word) !== false
)
$points += 2;
if (strpos($_POST['comments'], "http://") !== false || strpos($_POST['comments'], "www.") !== false)
$points += 2;
if (isset($_POST['nojs']))
$points += 1;
if (preg_match("/(<.*>)/i", $_POST['comments']))
$points += 2;
if (strlen($_POST['name']) < 3)
$points += 1;
if (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500))
$points += 2;
if (preg_match("/[bcdfghjklmnpqrstvwxyz]{7,}/i", $_POST['comments']))
$points += 1;
// end score assignments
foreach($requiredFields as $field) {
trim($_POST[$field]);
if (!isset($_POST[$field]) || empty($_POST[$field]) && array_pop($error_msg) != "Please fill in all the required fields and submit again.\r\n")
$error_msg[] = "Please fill in all the required fields and submit again.";
}
if (!empty($_POST['name']) && !preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name'])))
$error_msg[] = "The name field must not contain special characters.\r\n";
if (!empty($_POST['email']) && !preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email'])))
$error_msg[] = "That is not a valid e-mail address.\r\n";
if ($error_msg == NULL && $points <= $maxPoints) {
$subject = "New Payment";
$message = "Here is a new applicant: \n\n";
foreach ($_POST as $key => $val) {
if (is_array($val)) {
foreach ($val as $subval) {
$message .= ucwords($key) . ": " . clean($subval) . "\r\n";
}
} else {
$message .= ucwords($key) . ": " . clean($val) . "\r\n";
}
}
$message .= "\r\n";
// this means reply to the sender with e-mail and subject.
if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {
$headers = "From: $yourEmail\r\n";
$headers .= "Reply-To: {$_POST['email']}\r\n";
} else {
$headers = "From: $yourWebsite <$yourEmail>\r\n";
$headers .= "Reply-To: {$_POST['email']}\r\n";
}
if (mail($yourEmail,$subject,$message,$headers)) {
if (!empty($thanksPage)) {
header("Location: $thanksPage");
exit;
} else {
$result = 'Congratulations! We have received your application. IMPORTANT Click link below';
$disable = true;
}
} else {
$error_msg[] = 'Your mail could not be sent this time. ['.$points.']';
}
} else {
if (empty($error_msg))
$error_msg[] = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']';
}
}
function get_data($var) {
if (isset($_POST[$var]))
echo htmlspecialchars($_POST[$var]);
}
?>
使用Cc:
SMTP头发送副本怎么样
// this means reply to the sender with e-mail and subject.
if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {
$headers = "From: $yourEmail\r\n";
$headers .= "Cc: {$_POST['email']}\r\n";
$headers .= "Reply-To: {$_POST['email']}\r\n";
} else {
$headers = "From: $yourWebsite <$yourEmail>\r\n";
$headers .= "Cc: {$_POST['email']}\r\n";
$headers .= "Reply-To: {$_POST['email']}\r\n";
}
但是,我不能保证您的服务器会接受使用假发件人发送邮件,也不能保证用户的邮件服务器不会拒绝该邮件。将多个收件人添加为逗号分隔字符串:
$yourEmail = "a@a.com, b@b.com";
mail($yourEmail,$subject,$message,$headers)
$to = $_POST['email'] . ', ' . $yourEmail;
mail($yourEmail,$subject,$message,$headers)
谢谢,但这将只发送给我想要的任何电子邮件,而不是表单的提交者。这是一个例子,表明你可以通过逗号分隔一次发送到多个地址。请不要对我大喊大叫;)好的,我看到了前两行,我想我没有看到其他两行。我应该把这个放在哪里,放在代码的顶部?再次感谢。这非常有效,发件人如何能够看到收到电子邮件的人的电子邮件。如果我更改$headers.=“Cc:{$\u POST['email']}\r\n”;至$headers.=“发件人:{$\u POST['email']}\r\n”;它会工作吗?谢谢你的回答,现在我有另一个问题,发件人必须在收据中接收此字段,而不是所有字段,因为我必须接收它们$requiredFields=“name,lastname,email,Phone”有没有办法在if和ELSE中包含这些内容?
$yourEmail = "a@a.com, b@b.com";
mail($yourEmail,$subject,$message,$headers)
$to = $_POST['email'] . ', ' . $yourEmail;
mail($yourEmail,$subject,$message,$headers)