Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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 如何检查收件人';s的电子邮件地址没有输入错误_Php_Email - Fatal编程技术网

Php 如何检查收件人';s的电子邮件地址没有输入错误

Php 如何检查收件人';s的电子邮件地址没有输入错误,php,email,Php,Email,我需要向我的客户发送订单确认书。销售人员询问客户的电子邮件地址。但如果销售人员在写下电子邮件地址时打错了字,我如何检查 我有一段来自php.net的代码。它检查收件人域和电子邮件格式,但不检查电子邮件是否存在 假设客户的电子邮件是这样的:someone@domain.com 代码输出如下: 电子邮件someone@domain.com,0=不正常,1=正常:1 您最多能做的就是 a) 使用正则表达式检查输入的字符串是否为有效的电子邮件地址 b) 要求输入两次电子邮件,禁止复制/粘贴,比较和验证

我需要向我的客户发送订单确认书。销售人员询问客户的电子邮件地址。但如果销售人员在写下电子邮件地址时打错了字,我如何检查

我有一段来自php.net的代码。它检查收件人域和电子邮件格式,但不检查电子邮件是否存在

假设客户的电子邮件是这样的:someone@domain.com

代码输出如下:

电子邮件someone@domain.com,0=不正常,1=正常:1
您最多能做的就是

a) 使用正则表达式检查输入的字符串是否为有效的电子邮件地址

b) 要求输入两次电子邮件,禁止复制/粘贴,比较和验证


我认为对电子邮件地址运行拼写检查是没有意义的。

除非您拥有整个Internet上所有邮件服务器的所有用户的所有电子邮件地址,否则您无法检查它!你怎么知道,那
somepne@domain.com
不是有效的电子邮件地址吗?如果您想验证用户的电子邮件地址,请向该地址发送电子邮件,并让用户确认接收。我不知道这是否正确。我只是假设这是一个打字错误。关于这个问题的其他参考资料可能需要让销售人员输入两次电子邮件地址,并在我的销售脚本中进行比较。禁止复制/粘贴也是一个好主意。这个脚本已经验证了地址的语法。我不认为输入两次会有任何帮助。记得那个人在电话里听到电子邮件,我猜(?)然后在电脑里打字。一个简单的例子是“mopy”,如果你听到有人说你假设它是“moby”,那么输入两次不会有任何区别。金标准是发送电子邮件到地址进行检查,而不是这个地址。+Andreas你有一个很好的理由,那就是不要让他们输入两次,因为销售人员确实会在电话中听到电子邮件。
<?
/*
This script validates an e-mail adress using getmxrr and fsockopen

1. it validates the syntax of the address.
2. get MX records by hostname
3. connect mail server and verify mailbox(using smtp command RCTP TO:<email>)
When the function "validate_email([email])" fails connecting the mail server with the highest priority in the MX record it will continue with the second mail server and so on..
The function "validate_email([email])" returns 0 when it failes one the 3 steps above, it will return 1 otherwise
*/

$email = "someone@domain.com";
echo "email $email, 0= not ok, 1= ok : ".validate_email($email)."<br>";
$email = "someone@domain.co";
echo "email $email, 0= not ok, 1= ok : ".validate_email($email)."<br>";
$email = "somepne@domain.com";
echo "email $email, 0= not ok, 1= ok : ".validate_email($email)."<br>";

function validate_email($email){
   $mailparts=explode("@",$email);
   $hostname = $mailparts[1];

   // validate email address syntax
   $exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$^";
   $b_valid_syntax=preg_match($exp, $email);

   // get mx addresses by getmxrr
   $b_mx_avail=getmxrr( $hostname, $mx_records, $mx_weight );
   $b_server_found=0;

   if($b_valid_syntax && $b_mx_avail){
     // copy mx records and weight into array $mxs
     $mxs=array();

     for($i=0;$i<count($mx_records);$i++){
       $mxs[$mx_weight[$i]]=$mx_records[$i];
     }

     // sort array mxs to get servers with highest prio
     ksort ($mxs, SORT_NUMERIC );
     reset ($mxs);

     while (list ($mx_weight, $mx_host) = each ($mxs) ) {
       if($b_server_found == 0){

         //try connection on port 25
         $fp = @fsockopen($mx_host,25, $errno, $errstr, 2);
         if($fp){
           $ms_resp="";
           // say HELO to mailserver
           $ms_resp.=send_command($fp, "HELO microsoft.com");

           // initialize sending mail
           $ms_resp.=send_command($fp, "MAIL FROM:<support@microsoft.com>");

           // try receipent address, will return 250 when ok..
           $rcpt_text=send_command($fp, "RCPT TO:<".$email.">");
           $ms_resp.=$rcpt_text;

           if(substr( $rcpt_text, 0, 3) == "250")
             $b_server_found=1;

           // quit mail server connection
           $ms_resp.=send_command($fp, "QUIT");

         fclose($fp);

         }

       }
    }
  }
  return $b_server_found;
}

function send_command($fp, $out){

  fwrite($fp, $out . "\r\n");
  return get_data($fp);
}

function get_data($fp){
  $s="";
  stream_set_timeout($fp, 2);

  for($i=0;$i<2;$i++)
    $s.=fgets($fp, 1024);

  return $s;
}

// support windows platforms
if (!function_exists ('getmxrr') ) {
  function getmxrr($hostname, &$mxhosts, &$mxweight) {
    if (!is_array ($mxhosts) ) {
      $mxhosts = array ();
    }

    if (!empty ($hostname) ) {
      $output = "";
      @exec ("nslookup.exe -type=MX $hostname.", $output);
      $imx=-1;

      foreach ($output as $line) {
        $imx++;
        $parts = "";
        if (preg_match ("/^$hostname\tMX preference = ([0-9]+), mail exchanger = (.*)$/", $line, $parts) ) {
          $mxweight[$imx] = $parts[1];
          $mxhosts[$imx] = $parts[2];
        }
      }
      return ($imx!=-1);
    }
    return false;
  }
}

?>