如今借助三方邮箱和短信验证注册越来越普及,为方便初学者,特分两部分讲解基于php的最简单的邮件发送与短信发送,长话短说 php本身并没有自带的邮件类库,实现邮件功能,简单的方法就是依赖email类来实现,尾部我会附上email类下载地址 下载完成以后,首先将
如今借助三方邮箱和短信验证注册越来越普及,为方便初学者,特分两部分讲解基于php的最简单的邮件发送与短信发送,长话短说
php本身并没有自带的邮件类库,实现邮件功能,简单的方法就是依赖email类来实现,尾部我会附上email类下载地址
下载完成以后,首先将该类解压至你项目目录下,位置随意
首先看一下目录结构
结构还是比较简单的
docs---扩展(按需删除)
example---demo示例(可删除)
language---语言包(必须)
test--测试文件(可删除)
aboutus.html---说明(可删除)
ChangeLog.txt---日志(可删除)
class.phpmailer.php---发送类(必须)
calss.pop3.php--pop3扩展(按需删除)
class.smtp.php--核心类stmp(必须)
docs.ini--配置项 按需修改
这里只介绍写简单的发送功能,其他功能以后将细细说明,那就开始吧
require("email/class.phpmailer.php");
$mail = new PHPMailer(); //建立邮件发送类
$address = '收件人地址';//收件人地址
$mail->IsSMTP(); // 使用SMTP方式发送
$mail->Host = "smtp.sohu.com"; // 您的企业邮局域名,我使用的是sohu邮箱 后面将付上常用邮箱的域名
$mail->SMTPAuth = true; // 启用SMTP验证功能
$mail->Username = ""; // 邮局用户名(请填写完整的email地址)也就是发件人邮箱
$mail->Password = "xxxxx";// 发件人邮箱密码
$mail->From = "";//邮件发送者email地址
$mail->FromName = "阿升";//发件人姓名
$mail->AddAddress($address, "");//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")
$mail->Subject = "测试"; //邮件标题
$mail->Body = "";//邮件主体这边由你编辑,注意,为了安全考虑最好进行一下转码(链接urlencode)和加密(md5)
//$mail->AltBody = "附加信息"; //附加信息,可以省略
$mail->Send();//发送邮件 成功返回true,失败返回false
?>
个人邮箱由于受限制和反垃圾邮件过滤 可能会多次失败,请解除测试收件箱的反垃圾功能
测试账号发送成功
附件
php-email类下载地址:http://download.csdn.net/detail/zhangsheng_1992/8544575
常见邮箱域名
163邮箱smtp.163.com
qq邮箱smtp.qq.com
新浪smtp.sina.com
搜狐邮箱smtp.sohu.com

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor