dqc2017 2014-06-11 13:26
浏览 34

零星的php表单邮件

I am using a php email form on different websites that works sporadically. Sometimes the email gets sent, sometimes it disappears into a black hole. This happens on different servers (Dreamhost, Bluehost). The emails are not showing up in spam.

I have a hidden field labeled "URL" that I use in an attempt to stop spam bots. Is it possible that's what's tripping it up? It makes no sense to me that it can work sometimes and not work other times.

This is the code:

    $thebox = "<textarea name='comment' rows='9' cols='70' wrap='hard' style='background-color: #E8E8E8;'></textarea>";
    $error_name = "";
    $error_email = "";
    $error_message = "";

 if(!isset($_POST['submit'])) {
    $name = "";
    $email = "";
}   

if(isset($_POST['submit']))
{
    $url = cleanup($_POST['url']);          // this field should be empty 
            if (!empty($url)) { exit; }     // if it's not, exit the script       

    $name=cleanup($_POST['name']);
    $email=cleanup($_POST['email']);
    $message=cleanup($_POST['comment']);
    $subject="Email sent via MyWebsite.com website";

                    $find   = array("
", "
", "", "

");
                    $message = str_replace( $find, "<br />",$message);
                    $message = stripslashes($message);
                    $MailTo="info@MyWebsite.com";                        

    $bad_name="Please fill in your name.";
    $bad_email="Please provide a valid e-mail address.";
    $bad_message="You forgot to type in a message.";
    $error = 0;

    $error_message="";
        if ((empty($message)) || (strlen($message)<5 ) )
            {
                $error_message = $bad_message;
                $error = 1;
            }

        if (!empty($message))
            {
        $thebox="<textarea name='comment' rows='9' cols='70' wrap='hard' style='background-color: #E8E8E8;'>".$message."</textarea>";
            }

        if ((!preg_match("/^([a-zA-Z0-9._])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/", $email)) || (empty($email) ) )
                {
                    $error = 1;
                    $error_email = $bad_email;
                }
        if (empty($name))
            {
                $error = 1;
                $error_name = $bad_name;
            }

    if (!empty($name) && !empty($email) && !empty($message) && $error==0)
    {


    $header = "From: '$name' <$email>
" .
        "Reply-To: $email
".
        "Return-Path: $email
".
        'X-Mailer: PHP/' . phpversion() . "
" .
        "MIME-Version: 1.0
" .
        "Content-Type: text/html; charset=utf-8
" .
        "Content-Transfer-Encoding: 8bit

";

    $Body = $message;

 mail ($MailTo, $subject, $Body, $header);

            echo "<p> &nbsp; </p> <p> &nbsp; </p>
                <h3>
                Your email has been sent.
                Thank you!
                </h3>
                <p> &nbsp; </p> <p> &nbsp; </p><p> &nbsp; </p> <p> &nbsp; </p>";
  • 写回答

1条回答 默认 最新

  • doudui9516 2014-06-12 13:38
    关注

    I'm answering my own question in case anyone else runs into this issue. The problem was indeed on the server side with both hosts. As part of an effort to stop email spoofing, they look at the "From" field.

    In Dreamhost's case, they do not allow the "From" field to be coming from anywhere other than a Dreamhost server. With Bluehost, it has to be a valid email address that they are able to trace back. (I used a made-up email address in my tests.)

    The work-around I used in both cases was to not use the visitor's email address in the "From" field. I am using my own email address in that field and putting the visitor's email address in the "Reply To" field instead.

    I already have a cleanup function to check any data that's returned. In addition, I added another layer of protection to make sure nothing is inserted into the header fields using this code:

    $email= urldecode($email);
    if (eregi("(|
    )", $email)) {exit();}
    

    I hope this information is of some help.

    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真