首页 > 编程技术 > php

判断字符串emailAddr是否为合法的email格式

发布时间:2016-11-25 17:04

/**
 * 判断字符串emailAddr是否为合法的email格式
 * 主要判断'@'及'.'是否出现,以及两者的位置
 * @param emailAddr 输入的email地址
 * @return true/false。
 */
function emailCheck(emailAddr)
{
      if((emailAddr == null) || (emailAddr.length < 2)) return false ;
      // 需出现'@',且不在首字符.
      var aPos = emailAddr.indexOf("@" ,1) ;
      if(aPos < 0)
      {
     return false ;
      }
      // '@'后出现'.',且不紧跟其后.
      if(emailAddr.indexOf("." ,aPos+2) < 0)
      {
     return false ;
      }
      return true ;
}
下面是我找到的一个直接使用smtp发送邮件的php例子程序(经改编), 但是服务器方总是提示: 550 system busy! 并且邮件无法发送.
那位知道如何处理?
另: 对于smtp服务器需要密码的情况该如何处理验证呢?
sory , 刚刚看到 smtp 发送邮件的问题 (链接的这个帖子怎么不是精华?, 建议斑竹给一个啊).
问题已经解决:
1. 命令data应该是"DATA "
2. from和to命令应该有, 否则一些server拒发邮件
3.使用base64_encode 加密用户名和密码
<?php
require("phpmail.php");
?>
<?
$smtp = "smtp.163.net";
$from ="hylpro@163.net";
$to = "hylpro@163.net";
$subject ="Hello php mail";
$message="Hello! this is a test use php";
$mail = new mail($smtp,"Welcom use this mail",true);
$mail->send( $to,$from,$subject,$message);
?>

<?
//---------------
// 实现SMTP
//---------------
class Mail{
var $lastmessage; //记录最后返回的响应信息
var $lastact; //最后的动作,字符串形式
var $welcome; //用在HELO后面,欢迎用户
var $debug; //是否显示调试信息
var $smtp; //smtp服务器
var $port; //smtp端口号
var $fp; //socket句柄
//Construct
function mail($smtp, $welcome="", $debug=false)
{
if(empty($smtp)) die("SMTP cannt be NULL!");
$this->smtp=$smtp;
if(empty($welcome))
{
$this->welcome=gethostbyaddr("localhost");
}
else
$this->welcome=$welcome;
$this->debug=$debug;
$this->lastmessage="";
$this->lastact="";
$this->port="25";
}
//
function show_debug($message, $inout)
{
if ($this->debug)
{
if($inout=="in") //响应信息
{
$m="<b> 收: </b>";
}
else
$m="<b> 发: </b>" ;
if(!ereg("n$", $message))
$message .= " ";
本文出自: 作者: (2001-11-23 09:08:00)
第二步:转发主机到目的主机
R: 220 BBN-VAX.ARPA Simple Mail Transfer Service Ready
S: HELO USC-ISIE.ARPA
R: 250 BBN-VAX.ARPA
 
S: MAIL FROM:<@USC-ISIE.ARPA:JQP@MIT-AI.ARPA>
R: 250 OK
 
S: RCPT TO:<Jones@BBN-VAX.ARPA>
R: 250 OK
 
S: DATA
R: 354 Start mail input; end with <CRLF>.<CRLF>
S: Received: from MIT-AI.ARPA by USC-ISIE.ARPA ;
2 Nov 81 22:40:10 UT
S: Date: 2 Nov 81 22:33:44
S: From: John Q. Public <JQP@MIT-AI.ARPA>
S: Subject: The Next Meeting of the Board
S: To: Jones@BBN-Vax.ARPA
S:
S: Bill:
S: The next meeting of the board of directors will be
S: on Tuesday.
S: John.
S: .
R: 250 OK
 
S: QUIT
R: 221 USC-ISIE.ARPA Service closing transmission channel
    
确认和发送
R: 220 SU-SCORE.ARPA Simple Mail Transfer Service Ready
S: HELO MIT-MC.ARPA
R: 250 SU-SCORE.ARPA
 
S: VRFY Crispin
R: 250 Mark Crispin <Admin.MRC@SU-SCORE.ARPA>
 
S: SEND FROM:<EAK@MIT-MC.ARPA>
R: 250 OK
 
S: RCPT TO:<Admin.MRC@SU-SCORE.ARPA>
R: 250 OK
 
S: DATA
R: 354 Start mail input; end with <CRLF>.<CRLF>
S: Blah blah blah...
S: ...etc. etc. etc.
S: .
R: 250 OK
 
S: QUIT
R: 221 SU-SCORE.ARPA Service closing transmission channel
    
获得和发送邮件 首先确定用户名,然后尝试将邮件发送到用户终端,
当它失败时,发送到用户邮箱。
R: 220 SU-SCORE.ARPA Simple Mail Transfer Service Ready
S: HELO MIT-MC.ARPA
R: 250 SU-SCORE.ARPA
 
S: VRFY Crispin
R: 250 Mark Crispin <Admin.MRC@SU-SCORE.ARPA>
 
S: SEND FROM:<EAK@MIT-MC.ARPA>
R: 250 OK
 
S: RCPT TO:<Admin.MRC@SU-SCORE.ARPA>
<?php
if ($EMAIL_INC) return;
$EMAIL_INC=    "defined";
define( "SmtpPort",25);
class Pop3 {
    var $subject;             // 邮件主题    
    var $from_email;               // 发件人地址
    var $from_name;              // 发件人姓名
    var $to_email;               // 收件人地址
    var $to_name;             // 收件人姓名
    var $body;              // 邮件内容
    var $filename;               // 文件名
    var $socket;            // 当前的 socket
    var $Line;
    var $Status;
    function pop3_open($server, $port)     
    {
        $this->Socket = fsockopen($server, $port);
        if ($this->Socket <= 0){
       return false;
        }
    $this->Line = fgets($this->Socket, 1024);
    $this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
    $this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);
function build_text_body($body) {
        return " <pre>".$this->make_link_clickable($this->linesize(htmlspecialchars($body),85))."</pre> ";
    }
    function decode_qp($text) {
        $text = quoted_printable_decode($text);
        /*
        $text = str_replace("","",$text);
        $text = ereg_replace("= ", "", $text);
        $text = str_replace(" "," ",$text);
        */
        $text = ereg_replace("=", "", $text);
        return $text;
    }
    function make_link_clickable($text){
        $text = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
       "<a class="autolink" href="1://23" target="_new">1://23</a>", $text);
        $text = eregi_replace("([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*.[a-z]{2,3})","<a class="autolink"    href="newmsg.php?mailto=1&nameto=1">1</a>", $text);
        return $text;
    }
    function process_message($header,$body) {
        global $mime_show_html;
        $mail_info = $this->get_mail_info($header);
标签:[!--infotagslink--]

您可能感兴趣的文章: