• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP简单实现发送邮件和防被当成垃圾邮件处理

php 搞代码 3年前 (2022-01-21) 32次浏览 已收录 0个评论
文章目录[隐藏]

这篇文章主要介绍了关于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 "发送成功!";?>


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP简单实现发送邮件和防被当成垃圾邮件处理

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址