Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP表单邮件不会返回带有@yahoo.com地址的条目_Php_Forms_Yahoo Mail - Fatal编程技术网

PHP表单邮件不会返回带有@yahoo.com地址的条目

PHP表单邮件不会返回带有@yahoo.com地址的条目,php,forms,yahoo-mail,Php,Forms,Yahoo Mail,表单邮件预期结果:姓名、电子邮件地址和信息发送至网站所有者@yahoo.com 表格要求。 姓名: 电邮: 信息: 当前状态: 如果@yahoo电子邮件地址放在表单的“email”字段中,(实际电子邮件地址@yahoo.com)不会收到电子邮件。如果“Email”字段使用@gmail.com或@godaddy.com填写地址,则该字段有效!下面是表单的HTML和send.php代码 谢谢你的帮助 <!-- CONTACT FORM -->

表单邮件预期结果:姓名、电子邮件地址和信息发送至网站所有者@yahoo.com

表格要求。 姓名: 电邮: 信息:

当前状态: 如果@yahoo电子邮件地址放在表单的“email”字段中,(实际电子邮件地址@yahoo.com)不会收到电子邮件。如果“Email”字段使用@gmail.com或@godaddy.com填写地址,则该字段有效!下面是表单的HTML和send.php代码

谢谢你的帮助

<!-- CONTACT FORM -->           
                    <div id="contact_form" class="animated fadeInDown">
                        
                        <!-- Success Message -->
                        <div class="form-success">
                            <p><i class="fa fa-check"></i>Thank you, your message has been sent!</p>
                        </div>
                        
                        <!-- Begin form -->
                        <div class="contact-form"> 
                            <form action="contact-form/send.php" method="post" class="form">    
                                <div class="name">
                                    <input class="text" type="text" name="name" placeholder="Name"> 
                                </div>
                                <div class="email">  
                                    <input class="text" type="text" name="email" placeholder="Email"> 
                                </div>
                                <div class="message">    
                                    <textarea name="message" rows="8" cols="60" placeholder="Message & Phone Number"></textarea> 
                                                                    
                                </div>
                                
                                <div class="bt-contact">
                                    <a class="btn-color btn-color-1d" id="submit" href="javascript:;"><span>SEND EMAIL</span></a>
                                    
                                </div>
                                    
                                <div class="loading"></div>
                                
                            </form> 
                        </div>
                        <!-- End form -->
                    </div>
                    <!-- END CONTACT FORM -->

谢谢,您的信息已经发送


如果您“从”任意地址发送邮件,这几乎肯定会被阻止,因为这被称为“欺骗”,很容易被检测为非法

您需要从您拥有和控制的地址发送

Yahoo对SPF记录非常严格,特别是DKIM,所以请确保这两个记录都已正确设置和验证

无论何时设置电子邮件表单工具,都要绝对确信有人不能劫持此工具将任意内容发送到任意地址。如果这是可能的,有人将不可避免地发现这一点,并使用它发送未经请求的邮件


您可以编辑您的问题并添加代码吗?我假设你的问题是为什么一封电子邮件没有发送到雅虎的电子邮件。谢谢你检查这个!该问题已被编辑并添加了代码。还包括您的
validator.php
文件。可能是问题的原因您的电子邮件很可能以垃圾邮件形式送达,因为您发送的域与发件人标头中的域不匹配。不是代表用户发送,而是通过雅虎的SMTP服务器转发电子邮件。好的,我会试试,谢谢!谢谢@tadman看了这个。我在网站上填写表单时使用合法的雅虎电子邮件地址,它们不会到达send.php脚本中指定的To:yahoo地址。来自其他域的所有其他电子邮件测试都有效。您不能通过自己的服务器从:…@yahoo.com
发送电子邮件。这是欺骗,将被阻止。您必须从您控制且可以正确配置的域发送。
<?php
/*------------------------------------
       YOUR EMAIL GOES HERE
--------------------------------------*/
$to = '<a real email address@yahoo.com>';


//Retrieve form data. 
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$name = ($_GET['name']) ? $_GET['name'] : $_POST['name'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
$comment = ($_GET['comment']) ?$_GET['comment'] : $_POST['message'];

//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;

//Include email validator
    require 'email-validator.php';
    $validator = new EmailAddressValidator();
    
//Simple server side validation for POST data, of course, you should validate the email
if (!$name) $errors[count($errors)] = 'Please enter your name.';
if (!$email) $errors[count($errors)] = 'Please enter your email.'; 
if (!$comment) $errors[count($errors)] = 'Please enter your comment.'; 

$email = strip_tags($email);

if (!$validator->check_email_address($email)) {
    $errors[count($errors)] = 'Invalid email address.'; 
}

//if the errors array is empty, send the mail
if (!$errors) {

    //sender
    $from = $name . ' <' . $email . '>';
    
    //Structure of the message:
    $subject = 'Message from ' . $name; 
    $message = '
    <!DOCTYPE html>
    <head></head>
    <body>
    <table>
        <tr><td>Name:</td><td>' . $name . '</td></tr>
        <tr><td>Email:</td><td>' . $email . '</td></tr>
        <tr><td>Message:</td><td>' . nl2br($comment) . '</td></tr>
    </table>
    </body>
    </html>';

    //End of the message structure
    
    
    //send the mail
    $result = sendmail($to, $subject, $message, $from);
    
    //if POST was used, display the message straight away
    if ($_POST) {
        if ($result) echo 'Thank you! We have received your message.';
        else echo 'Sorry, unexpected error. Please try again later';
        
    //else if GET was used, return the boolean value so that 
    //ajax script can react accordingly
    //1 means success, 0 means failed
    } else {
        echo $result;   
    }

//if the errors array has values
} else {
    //display the errors message
    for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
    echo '<a href="../contact.html">Back</a>';
    exit;
}


//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= 'From: ' . $from . "\r\n";
    
    $result = mail($to,$subject,$message,$headers);
    
    if ($result) return 1;
    else return 0;
}

?>
<?php

    class EmailAddressValidator {

        /**
         * Check email address validity
         * @param   strEmailAddress     Email address to be checked
         * @return  True if email is valid, false if not
         */
        public function check_email_address($strEmailAddress) {
            
            // If magic quotes is "on", email addresses with quote marks will
            // fail validation because of added escape characters. Uncommenting
            // the next three lines will allow for this issue.
            //if (get_magic_quotes_gpc()) { 
            //    $strEmailAddress = stripslashes($strEmailAddress); 
            //}

            // Control characters are not allowed
            if (preg_match('/[\x00-\x1F\x7F-\xFF]/', $strEmailAddress)) {
                return false;
            }

            // Check email length - min 3 (a@a), max 256
            if (!$this->check_text_length($strEmailAddress, 3, 256)) {
                return false;
            }

            // Split it into sections using last instance of "@"
            $intAtSymbol = strrpos($strEmailAddress, '@');
            if ($intAtSymbol === false) {
                // No "@" symbol in email.
                return false;
            }
            $arrEmailAddress[0] = substr($strEmailAddress, 0, $intAtSymbol);
            $arrEmailAddress[1] = substr($strEmailAddress, $intAtSymbol + 1);

            // Count the "@" symbols. Only one is allowed, except where 
            // contained in quote marks in the local part. Quickest way to
            // check this is to remove anything in quotes. We also remove
            // characters escaped with backslash, and the backslash
            // character.
            $arrTempAddress[0] = preg_replace('/\./'
                                             ,''
                                             ,$arrEmailAddress[0]);
            $arrTempAddress[0] = preg_replace('/"[^"]+"/'
                                             ,''
                                             ,$arrTempAddress[0]);
            $arrTempAddress[1] = $arrEmailAddress[1];
            $strTempAddress = $arrTempAddress[0] . $arrTempAddress[1];
            // Then check - should be no "@" symbols.
            if (strrpos($strTempAddress, '@') !== false) {
                // "@" symbol found
                return false;
            }

            // Check local portion
            if (!$this->check_local_portion($arrEmailAddress[0])) {
                return false;
            }

            // Check domain portion
            if (!$this->check_domain_portion($arrEmailAddress[1])) {
                return false;
            }

            // If we're still here, all checks above passed. Email is valid.
            return true;

        }

        /**
         * Checks email section before "@" symbol for validity
         * @param   strLocalPortion     Text to be checked
         * @return  True if local portion is valid, false if not
         */
        protected function check_local_portion($strLocalPortion) {
            // Local portion can only be from 1 to 64 characters, inclusive.
            // Please note that servers are encouraged to accept longer local
            // parts than 64 characters.
            if (!$this->check_text_length($strLocalPortion, 1, 64)) {
                return false;
            }
            // Local portion must be:
            // 1) a dot-atom (strings separated by periods)
            // 2) a quoted string
            // 3) an obsolete format string (combination of the above)
            $arrLocalPortion = explode('.', $strLocalPortion);
            for ($i = 0, $max = sizeof($arrLocalPortion); $i < $max; $i++) {
                 if (!preg_match('.^('
                                .    '([A-Za-z0-9!#$%&\'*+/=?^_`{|}~-]' 
                                .    '[A-Za-z0-9!#$%&\'*+/=?^_`{|}~-]{0,63})'
                                .'|'
                                .    '("[^\\\"]{0,62}")'
                                .')$.'
                                ,$arrLocalPortion[$i])) {
                    return false;
                }
            }
            return true;
        }

        /**
         * Checks email section after "@" symbol for validity
         * @param   strDomainPortion     Text to be checked
         * @return  True if domain portion is valid, false if not
         */
        protected function check_domain_portion($strDomainPortion) {
            // Total domain can only be from 1 to 255 characters, inclusive
            if (!$this->check_text_length($strDomainPortion, 1, 255)) {
                return false;
            }
            // Check if domain is IP, possibly enclosed in square brackets.
            if (preg_match('/^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])'
               .'(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}$/'
               ,$strDomainPortion) || 
                preg_match('/^\[(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])'
               .'(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}\]$/'
               ,$strDomainPortion)) {
                return true;
            } else {
                $arrDomainPortion = explode('.', $strDomainPortion);
                if (sizeof($arrDomainPortion) < 2) {
                    return false; // Not enough parts to domain
                }
                for ($i = 0, $max = sizeof($arrDomainPortion); $i < $max; $i++) {
                    // Each portion must be between 1 and 63 characters, inclusive
                    if (!$this->check_text_length($arrDomainPortion[$i], 1, 63)) {
                        return false;
                    }
                    if (!preg_match('/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|'
                       .'([A-Za-z0-9]+))$/', $arrDomainPortion[$i])) {
                        return false;
                    }
                    if ($i == $max - 1) { // TLD cannot be only numbers
                        if (strlen(preg_replace('/[0-9]/', '', $arrDomainPortion[$i])) <= 0) {
                            return false;
                        }
                    }
                }
            }
            return true;
        }

        /**
         * Check given text length is between defined bounds
         * @param   strText     Text to be checked
         * @param   intMinimum  Minimum acceptable length
         * @param   intMaximum  Maximum acceptable length
         * @return  True if string is within bounds (inclusive), false if not
         */
        protected function check_text_length($strText, $intMinimum, $intMaximum) {
            // Minimum and maximum are both inclusive
            $intTextLength = strlen($strText);
            if (($intTextLength < $intMinimum) || ($intTextLength > $intMaximum)) {
                return false;
            } else {
                return true;
            }
        }

    }

?>