dping1968 2015-10-08 08:50
浏览 35

我的联系方式PHP Form每次提交都会发送7封电子邮件

Well my PHP contact us form is sending email too well
But I am getting 7 emails per submission
Problem is I have no idea why I am getting 7 emails per submission.
Any thoughts?

CODE

<?php

if(isset($_POST['Send'])){
    $first_name =trim($_POST['first_name']);
    $last_name=trim($_POST['last_name']);
    $phone_number=trim($_POST['phone_number']);
    $email=trim($_POST['email']);
    $msg=trim($_POST['msg']);
    $name=$first_name." ".$last_name;
    if($first_name == '' ||$last_name =='' || $phone_number == '' || $email == ''|| $msg == ''  ){
        $merror = "<p style='color:red;'> * Kindly fill all Fileds<p>";
    }else{
        foreach($_POST as $value){
            if(stripos($value, 'Content-Type:')!== FALSE || $_POST['Address']!== "" ) {
                $merror = "<p style='color:red;'> * The information you have entered has a problem</p>";
            }else{
                require_once "class.phpmailer.php";
                $mail= new PHPMailer();
                if(!$mail->ValidateAddress($email)){
                   $merror = "<p style='color:red;'> * Please enter a valid email address</p>"; 
                }else{
                    $email_body = "";
                    $email_body = $email_body . "Name: ". $name ."<br>";
                    $email_body = $email_body . "Phone: ". $phone_number. "<br>";
                    $email_body = $email_body . "Email: ". $email . "<br>";
                    $email_body = $email_body . "Message: " . $msg . "<br>";
                    $mail->SetFrom($email, $name);
                    $address = "s@example.co";
                    $mail->AddAddress($address, Trial);
                    $mail->Subject= "Ess contact form message ".$name;
                    //$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
                    $mail->MsgHTML($email_body);
                    if(!$mail->Send()) {
                        echo "Mailer Error: " . $mail->ErrorInfo;
                        echo"<script>window.open('Contact.php','_self')</script>";
                    } 
                    echo"<script>window.open('Contact.php?status=thanks','_self')</script>";    
                }
            }
        }
    }
}
?>
  • 写回答

1条回答 默认 最新

  • doujuegai8830 2016-04-05 16:42
    关注

    You also have a very common error a lot of people have with "Contact Us" forms.

      $mail->SetFrom($email, $name);
    

    This will break SPF and also cause DMARC to fail and you will never get the message from some people, if your mail server you use has DMARC enabled on it and GMAIL does.

    Since DMARC is a more recent protocol, a lot of the old cookie cutter code for contact us forms - doesn't take this into account.

    You can read more about that here: "DMARC - Contact Us Form Nightmare"

    The suggested workaround will be to do:

     $mail->SetFrom("<Your email Adddress>, $name);
    

    You have the the customers contact email in the body of the message which is perfect.

    This way - you avoid the issue outline in the article. You won't quickly be able to hit the "Reply" button, but at least you'll get the emails from those customers who have DMARC enabled.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错