这篇文章主要介绍了关于PHP简单实现发送邮件和防被当成垃圾邮件处理,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
邮件服务器使用的是163邮箱的
需要去163邮箱申请邮箱和设置客户端授权密码。
设置方法
登录163邮箱->设置->POP3/SMTP/IMAP->客户端授权密码
图片演示
设置好要记住!
下面就是代码了
表单
index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <title>PHP发邮件 - BY TANKING</title> <style type="text/css"> *{margin:0px;padding: 0px;} h3{ text-align: center; margin-top: 50px; } #form-p{ width: 300px; margin:20px auto; } #form-p .input_style{ width: 100%; height: 35px; font-size: 16px; text-indent: 5px; margin-bottom: 5px; } #form-p .textarea_style{ width: 100%; height: 65px; font-size: 16px; text-indent: 5px; resize: none; } #form-p .sendbtn{ width: 100%; height: 35px; font-size: 16px; cursor: pointer; margin-top: 5px; } #result .yes{ position: fixed; top: 0px; background: #5cb85c; width: 100%; height: 35px; line-height: 35px; text-align: center; color: #fff; font-weight: bold; } #result .no{ position: fixed; top: 0px; background: #c00; width: 100%; height: 35px; line-height: 35px; text-align: center; color: #fff; font-weight: bold; } </style></head><body><h3>PHP发邮件-BY TANKING</h3><p id="form-p"> <form action="mail.php" method="POST"> <input name="email" type="text" placeholder="接收邮箱" class="input_style"/><br/> <input name="title" type="text" placeholder="标题" class="input_style"/><br/> <input name="content" type="text" placeholder="内容" class="input_style"/><br/> <input type="submit" value="发送" class="sendbtn"/> </form></p></body></html>
提交表单
发送邮件处理
mail.php
<?php//获取表单提交的邮件标题$title = $_POST["title"];//获取表单提交的内容$content = $_POST["content"];include_once("smtp.class.php"); $smtpserver = "smtp.163.com"; //SMTP服务器 $smtpserverport = 25; //SMTP服务器端口 //获取表单提交的邮件接收人邮箱号码 $email = $_POST["email"]; $smtpusermail = "你的163邮箱地址"; //SMTP服务器的用户邮箱 $smtpuser = "你的163邮箱地址"; //SMTP服务器的用户帐号 $smtppass = "授权密码"; //SMTP服务器的授权密码 $smtp = new Smtp($smtpserver, $smtpserverport, true, $smtpuser, $smtppass); //这里面的一个true是表示使用身份验证,否则不使用身份验证. $emailtype = "HTML"; //信件类型,文本:tex<a>2本文来源gao*daima.com搞@代#码&网6</a><pre>搞gaodaima代码
t;网页:HTML $smtpemailto = $email; $smtpemailfrom = $smtpusermail; $emailsubject = $title; $emailbody = "<p>".$content."</p>"; //开始发送邮件 $smtp->sendmail($smtpemailto, $smtpemailfrom, $emailsubject, $emailbody, $emailtype); echo "发送成功!";?>