dongshen2903 2014-05-07 20:13
浏览 47

自动回复者发送给发件人/提交者的电子邮件

I just inherited a PHP form and what i need is that the submitter of the form receives a receipt of what they have just entered in the fields. This is what I have and not sure where to start.Everything else works fine and i get the email when they submit it, i just need them to receive a copy of it.

 <?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.
")
        $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.
";

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.
";



if ($error_msg == NULL && $points <= $maxPoints) {
    $subject = "New Payment";

    $message = "Here is a new applicant: 

";
    foreach ($_POST as $key => $val) {
        if (is_array($val)) {
            foreach ($val as $subval) {
                $message .= ucwords($key) . ": " . clean($subval) . "
";
            }
        } else {
            $message .= ucwords($key) . ": " . clean($val) . "
";
        }
    }
    $message .= "
";

    // this means reply to the sender with e-mail and subject.
    if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {
        $headers   = "From: $yourEmail
";
        $headers  .= "Reply-To: {$_POST['email']}
";
    } else {
        $headers   = "From: $yourWebsite <$yourEmail>
";
        $headers  .= "Reply-To: {$_POST['email']}
";
    }

    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]);
 }
  ?>

Thanks for the support, now another issue came up.

The sender has to receive this fields in the receipt and not all of them as i have to receive them. $requiredFields = "name,lastname,email,Phone" Any way to have this in the if and elses?

So in other words I receive all the fields and the senders receives 4 our of 5.

  • 写回答

2条回答 默认 最新

  • dongsheng8664 2014-05-07 20:18
    关注

    How about sending the copy using the Cc: SMTP header ?

    // this means reply to the sender with e-mail and subject.
    if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {
        $headers   = "From: $yourEmail
    ";
        $headers  .= "Cc: {$_POST['email']}
    ";
        $headers  .= "Reply-To: {$_POST['email']}
    ";
    } else {
        $headers   = "From: $yourWebsite <$yourEmail>
    ";
        $headers  .= "Cc: {$_POST['email']}
    ";
        $headers  .= "Reply-To: {$_POST['email']}
    ";
    }
    

    If you don't want the user to see to what address the mail has been originally sent, you can do the following : Send the mail primarily to the user, and include yourself as a blind carbon copy :

    // this means reply to the sender with e-mail and subject.
    if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {
        $headers   = "From: {$_POST['email']}
    ";
        $headers  .= "Bcc: $yourEmail
    ";
        $headers  .= "Reply-To: {$_POST['email']}
    ";
    } else {
        $headers   = "From: {$_POST['email']}
    ";
        $headers  .= "Bcc: $yourEmail
    ";
        $headers  .= "Reply-To: {$_POST['email']}
    ";
    }
    
    if (mail($_POST['email'],$subject,$message,$headers)) {
    

    However, I cannot guarantee that your server will accept to send the mail with a fake sender, nor that the mail server of the user won't reject it.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?