当前位置: 编程技术>php
本页文章导读:
▪php email检测类(附示例) php实现的email检测类,判断email格式的正确性。
代码:
<?
//email格式检测
class check_email{
private $email;
private $exp="%^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z].........
▪php实现的基于文本模板的邮件发送类 一个php email邮件发送类,可以构造简单的邮件格式,效果不错。
代码:
<?
/**
* php email邮件发送类
* 编辑:www.
*/
class cls_email_module
{
function mailSend($tomail,$frommail,$subj,$message,$html="").........
▪php实例:email验证类 验证email地址的格式是否正确,代码如下:
<?php
/**
* Email验证类
* 根据正则验证email格式是否正确
* N.B. 'a' in 'a_email' stands for Alberon not the pronoun!
*
*/
class a_email
{
/**
* 电子.........
[1]php email检测类(附示例)
来源: 互联网 发布时间: 2013-12-24
php实现的email检测类,判断email格式的正确性。
代码:
<? //email格式检测 class check_email{ private $email; private $exp="%^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z])+$%"; private $success_txt; private $error_txt; /* * $email - 待检测email地址 * $exp - 正则验证 * $success_txt - email格式有效时的提示消息 * $error_txt - email格式无效时的错误消息 */ function result_txt($success_txt,$error_txt){ $this->success_txt=$success_txt; $this->error_txt=$error_txt; } function start_check($params){ $this->email=$params; if(preg_match($this->exp, $this->email)){ return $this->echo_result($this->email,true); /*输入的email格式有效*/ }else{ return $this->echo_result($this->email,false); /*输入的email格式无效*/ } } function echo_result($email,$result){ if($result){ return $email." [".$this->success_txt."]<br>"; }else{ return "<span >".$email."</span> [".$this->error_txt."]<br>"; } } } ?>
调用示例:
<? require_once("check.inc.php"); $email_1="test@test.te"; $email_2="test@testte"; $a=new check_email; /*Show text -> [如果email格式有效] [如果email格式无效] */ $a->result_txt("email格式有效","email格式无效"); echo $a->start_check($email_1); echo $a->start_check($email_2); ?>
[2]php实现的基于文本模板的邮件发送类
来源: 互联网 发布时间: 2013-12-24
一个php email邮件发送类,可以构造简单的邮件格式,效果不错。
代码:
<? /** * php email邮件发送类 * 编辑:www. */ class cls_email_module { function mailSend($tomail,$frommail,$subj,$message,$html="") { if($html) { $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .="From:$frommail"; } else { $headers .="From:$frommail"; } $sSubject = $subj; $sBody = $message; // Parsing body $body = $sBody; for($ptr = 0; $ptr < strlen($body); $ptr++) { switch($body[ $ptr ]) { case "{": $is_token = 1; $token = ""; break; case "}"; $is_token = 0; eval("global \$".strtolower($token).";"); eval("\$sVal = \$".strtolower($token).";"); $sBody = str_replace("{{$token}}", "$sVal", $sBody); $token = ""; break; } if(($body[ $ptr ] != "{" && $body[ $ptr ] != "}") && $is_token) { $token .= $body[ $ptr ]; } } $re=mail($tomail, $sSubject,$sBody,$headers); $toShow="<table cellpadding=2 cellspacing=0 border=0 bordercolor=#ffffff>"; $toShow.="<tr>"; $toShow.="<td bgcolor=#84C7FF><font face=arial size=2><b>Subject</b></font></td>"; $toShow.="<td bgcolor=#84C7FF><font face=arial size=2>$subj</font></td>"; $toShow.="</tr>"; $toShow.="<tr>"; $toShow.="<td bgcolor=#84C7FF><font face=arial size=2><b>Message</b></font></td>"; $toShow.="<td bgcolor=#84C7FF valign=top><font face=arial size=2>$sBody</font></td>"; $toShow.="</tr>"; $toShow.="</table>"; return $toShow; } }
调用示例:
<? include("email.php"); $msg='Hello {FNAME} {LNAME}, <br> 有关您的账号激活邮件。<br> username:: {USERNAME}<br> password:: {PASSWORD}<br>'; $sub="激活账号"; $from="admin@abc.com"; $to="user@pqr.com"; $email= new cls_email_module(); $fname="UsersFirstName"; $lname="UsersLastName"; $username="usernameF"; $password="usernameP"; $msg=$email->mailSend($to,$from,$sub,$msg); echo $msg; ?>
[3]php实例:email验证类
来源: 互联网 发布时间: 2013-12-24
验证email地址的格式是否正确,代码如下:
<?php /** * Email验证类 * 根据正则验证email格式是否正确 * N.B. 'a' in 'a_email' stands for Alberon not the pronoun! * */ class a_email { /** * 电子邮件地址 * * @var string */ var $email; /** * 错误消息 * * @var string */ var $error_html; /** * 构造函数 * * @param string $email * @return null */ function a_email($email) { $this->email = $email; } /** * 验证email格式 */ function email_is_valid() { $valid = true; if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,8})$", $this->email)) { $valid = false; $this->error_html = "$this->email is not properly formatted"; } return $valid; } } //调用示例 $tmp_mail = "test123@" $email = new a_email(); if ($email->email_is_valid()){ echo "email格式正确"; }else{ echo "对不起,您输入的email有误."; }
最新技术文章: