好!欢迎访问迷津渡口 现在时间是: 天气 °C ~ °C

迷津渡口

越感到迷惑 越接近真理

PHP教程-优雅判断邮箱的真实有效性:filter_var和checkdnsrr

从前PHP判断邮箱有效性只能利用正则表达式。正则表达式意味着繁琐!

其实现在使用html5的邮箱表单就可以解决大部分问题了:

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>HTML5 邮箱地址表单</title>
</head>
<body>
    <form action="" method="post" id="register"></form>
    <p>在提交前检查邮箱有效性,无效则无法提交</p>
    邮箱:<input type="email" name="email" value="" placeholder="请输入邮箱" required="required" form="register"><br/>
    <input type="submit" value="提交" form="register">
</body>
</html>

通过HTML5表单可以在提交前简单过滤一些不符合规则的邮箱地址。


在提交到服务器之后可以利用PHP进一步过滤:

filter_var函数判断邮箱格式是否符合规范;

checkdnsrr函数可以判断邮箱的主域是否真实有效,从而判断邮箱是否真实有效;

整合在一起就是下面的函数:

function checkMail($email) {
	if (filter_var($email, FILTER_VALIDATE_EMAIL) && checkdnsrr(array_pop(explode('@',$email)),"MX")) {
		return true;
	} else {
		return false;
	}
}


优雅从容有木有^_^

点赞4
   支持一下
挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
 点赞
 签到
 表情
 图片
 代码
提交评论

清空信息
关闭评论
debbiebissett
 debbiebissett 2018-12-10 10:04回复
#53
<a href="http://www.rivacover.com/scottie-pippen-portland-trail-blazers-jersey-nflr">scottie pippen portland trail blazers jersey</a> <a href="http://www.slimtobody.com/47-brand-black-boston-red-sox-hat-utah-hatg">47 brand black boston red sox hat utah</a> <a href="http://www.mgnmilitaria.com/braxton-miller-houston-texans-jersey-nflr">braxton miller houston texans jersey</a> <a href="http://www.rahwindsor.com/womens-plaid-nike-cortez-runninga">womens plaid nike cortez</a> <a href="http://www.ceethebarber.com/hermes-kelly-pochette-bag-hermesr">hermes kelly pochette bag</a> <a href="http://www.saatchixblog.com/bon-march%C3%A9-new-balance-999-femmes-rouge-sneakerf">bon march茅 new balance 999 femmes rouge</a>
debbiebissett http://www.debbiebissett.com/
myelectricrc
 myelectricrc 2018-12-03 03:23回复
#52
<a href="http://www.maisonbagshop.com/womens-nike-air-max-invigor-print-green-netherlands-shoeso">womens nike air max invigor print green netherlands</a> <a href="http://www.colixguides.com/nike-air-more-uptempo-where-to-buy-footf">nike air more uptempo where to buy</a> <a href="http://www.ammampart.com/nike-wmns-air-max-1-premium-white-ice-skog">nike wmns air max 1 premium white ice</a> <a href="http://www.besoksfolder.com/nike-paul-rodriguez-9-dam%C3%A4nner-blau-sportsg">nike paul rodriguez 9 dam盲nner blau</a> <a href="http://www.hiphoprapjam.com/ray-ban-cat-style-sunglasses-polarized-sunglassesg">ray ban cat style sunglasses polarized</a> <a href="http://www.mjnonghyup.com/dg-belt-mens-beltr">dg belt mens</a>
[url=http://www.myelectricrc.com/]myelectricrc[/url]
thankhuc
 thankhuc 2018-11-28 08:25回复
#51
<a href="http://www.diveintovideo.com/detroit-lions-71-riley-reiff-elite-jersey-white-pro-line-gold-collection-nfla">detroit lions 71 riley reiff elite jersey white pro line gold collection</a> <a href="http://www.moxiepouch.com/jordan-eclipse-red-and-white-skos">jordan eclipse red and white</a> <a href="http://www.weissewelt.com/billig-adidas-nmd-runner-menns-s%C3%B8lv-trainersb">billig adidas nmd runner menns s酶lv</a> <a href="http://www.rbengals.com/jackson-frank-jersey-online-nflb">jackson frank jersey online</a> <a href="http://www.onpointresale.com/nike-air-max-plus-iii-skow">nike air max plus iii</a> <a href="http://www.soaringcow.com/oakley-sunglasses-green-yoga-leggings-sunglassesd">oakley sunglasses green yoga leggings</a>
thankhuc http://www.thankhuc.com/
glassurchin
 glassurchin 2018-11-27 15:44回复
#50
<a href="http://www.moviezluv.com/nike-flyknit-air-max-black-white-turbo-green-volt-jack-runningc">nike flyknit air max black white turbo green volt jack</a> <a href="http://www.trulsbakken.com/a-buon-mercato-nike-air-huarache-light-maschio-bianca-skoe">a buon mercato nike air huarache light maschio bianca</a> <a href="http://www.dentaleden.com/lebron-13-colorful-black-lion-footg">lebron 13 colorful black lion</a> <a href="http://www.zovailangnews.com/colorado-avalanche-baseball-cap-hats">colorado avalanche baseball cap</a> <a href="http://www.charlesklamut.com/kyrie-1-kid-air-mag-sportsf">kyrie 1 kid air mag</a> <a href="http://www.ncctifton.com/nike-air-waffle-menns-bl%C3%A5-sportsd">nike air waffle menns bl氓</a>
glassurchin http://www.glassurchin.com/
matchyvintage
 matchyvintage 2018-11-26 18:44回复
#49
<a href="http://www.startnimble.com/asics-gel-kayano-21-herren-wei%C3%9F-trainersg">asics gel kayano 21 herren wei脽</a> <a href="http://www.tatteredhands.com/nike-air-max-plus-fuse-gpx-skou">nike air max plus fuse gpx</a> <a href="http://www.retainchoices.com/nike-flyknit-racer-hyper-orange-zest-shoesb">nike flyknit racer hyper orange zest</a> <a href="http://www.celineka.com/klay-thompson-jersey-men-nflr">klay thompson jersey men</a> <a href="http://www.ngencomputer.com/new-air-max-2017-womens-trainersce">new air max 2017 womens</a> <a href="http://www.hitsattitude.com/billig-nike-kobe-9-mid-kvinners-gull-skoe">billig nike kobe 9 mid kvinners gull</a>
matchyvintage http://www.matchyvintage.com/
veruccapedis
 veruccapedis 2018-11-25 01:03回复
#48
<a href="http://www.donnakaywhite.com/%EF%BB%BFhombres-nike-air-max-270-blanco-shoesn">锘縣ombres nike air max 270 blanco</a> <a href="http://www.karrealestate.com/order-canada-goose-jacket-online-canadagooser">order canada goose jacket online</a> <a href="http://www.busrockerz.com/red-moncler-bubble-jacket-monclerr">red moncler bubble jacket</a> <a href="http://www.ajupiter.com/nike-air-max-95-purple-canada-shoeso">nike air max 95 purple canada</a> <a href="http://www.cletalover.com/jordan-6-custom-infrared-carmine-sportsd">jordan 6 custom infrared carmine</a> <a href="http://www.nicakhtar.com/nike-free-run-coral-skou">nike free run coral</a>
nathansills
 nathansills 2018-11-24 17:58回复
#47
<a href="http://www.immoetvous.com/womens-nike-air-vapormax-plus-grey-shoesn">womens nike air vapormax plus grey</a> <a href="http://www.lapcomit.com/adidas-cc-ride-m-kids-shoes-orange-sportsa">adidas cc ride m kids shoes orange</a> <a href="http://www.mikeorlandoni.com/adidas-zx-flux-schwarz-and-rose-gold-dam%C3%A4nner-glasses-shoesv">adidas zx flux schwarz and rose gold dam盲nner glasses</a> <a href="http://www.dragongateusa.com/nike-free-2014-dam%C3%A4nner-orange-shoesc">nike free 2014 dam盲nner orange</a> <a href="http://www.pepinmystep.com/hermes-imprevisible-bracelet-jewelryr">hermes imprevisible bracelet</a> <a href="http://www.cantleylaw.com/air-max-2015-infrared-crimson-footc">air max 2015 infrared crimson</a>
nathansills http://www.nathansills.com/
qrsdeal
 qrsdeal 2018-11-21 06:51回复
#46
<a href="http://www.marijuanapier.com/air-max-90-se-women-shoesc">air max 90 se women</a> <a href="http://www.emazoncentral.com/2015-2016-real-madrid-scccer-uniform-short-sleeves-jersey-black-no-patch-one-the-sleeves-nflv">2015 2016 real madrid scccer uniform short sleeves jersey black no patch one the sleeves</a> <a href="http://www.pikespeakshop.com/black-purple-womens-under-armour-clutchfit-drive-shoes-trainersd">black purple womens under armour clutchfit drive shoes</a> <a href="http://www.lacosmeticink.com/kansas-city-royals-golf-hat-hatr">kansas city royals golf hat</a> <a href="http://www.klgateslaw.com/hermes-constance-bag-price-2016-hermesr">hermes constance bag price 2016</a> <a href="http://www.veronicaloman.com/adidas-zx-flux-schwarz-and-rose-gold-dam%C3%A4nner-glasses-shoesv">adidas zx flux schwarz and rose gold dam盲nner glasses</a>
qrsdeal http://www.qrsdeal.com/
kanpourakuen
 kanpourakuen 2018-11-21 02:48回复
#45
<a href="http://www.beaudoutjoel.com/hermes-dragonfly-scarf-scarfr">hermes dragonfly scarf</a> <a href="http://www.jewelsavers.com/pink-gold-mens-asics-gel-lyte-5-shoes-runningb">pink gold mens asics gel lyte 5 shoes</a> <a href="http://www.willymunoz.com/nike-air-max-90-ladies-pink-glitter-trainersd">nike air max 90 ladies pink glitter</a> <a href="http://www.tejarateparsi.com/billig-nike-lunarglide-8-dam%C3%A4nner-schwarz-sneakerf">billig nike lunarglide 8 dam盲nner schwarz</a> <a href="http://www.freemoviesaz.com/adidas-harden-vol-1-blue-silver-skob">adidas harden vol 1 blue silver</a> <a href="http://www.jneecedesigns.com/ralph-lauren-sport-hoodie-polor">ralph lauren sport hoodie</a>
kanpourakuen http://www.kanpourakuen.com/
dcssattorneys
 dcssattorneys 2018-11-18 10:43回复
#44
<a href="http://www.precisetrades.com/hermes-scarf-with-box-scarfr">hermes scarf with box</a> <a href="http://www.sterneanswers.com/moncler-jacket-womens-sale-monclerr">moncler jacket womens sale</a> <a href="http://www.ycbrowsbeauty.com/nike-air-force-1-id-pioneer-leather-runningc">nike air force 1 id pioneer leather</a> <a href="http://www.scalfarogroup.com/looking-for-canada-goose-jacket-canadagooser">looking for canada goose jacket</a> <a href="http://www.captmollie.com/nike-free-tr-fit-kvinners-bl%C3%A5-runninge">nike free tr fit kvinners bl氓</a> <a href="http://www.cutlaroc.com/ray-ban-sunglasses-code-check-engine-sunglassesc">ray ban sunglasses code check engine</a>
dcssattorneys http://www.dcssattorneys.com/
顶部留言底部
 00:00/00:00
我想和你虚度时光 - 花房姑娘(9)
  1. 我想和你虚度时光
  2. 花房姑娘
  3. 恋恋风尘
  4. 我喜爱一切不彻底的事物
  5. 我的心里是满的
  6. Long Way
  7. 给少年的歌
  8. 晴日共剪窗
  9. 天上的月你的脸