Home >Backend Development >PHP Tutorial >PHP uses the smtp class to send emails, phpsmtp class emails_PHP tutorial

PHP uses the smtp class to send emails, phpsmtp class emails_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:06:021004browse

php uses the smtp class to send emails. phpsmtp class emails

The smtp class method of sending emails is simple and stable. You can send emails with just a few lines of simple configuration. Not really looking forward to giving it a try!

The following is the core code:

<&#63;php
 require_once "email.class.php";
 //******************** 配置信息 ********************************
 $smtpserver = "smtp.126.com";//SMTP服务器
 $smtpserverport =25;//SMTP服务器端口
 $smtpusermail = "new2008oh@126.com";//SMTP服务器的用户邮箱
 $smtpemailto = $_POST['toemail'];//发送给谁
 $smtpuser = "new2008oh";//SMTP服务器的用户帐号
 $smtppass = "您的邮箱密码";//SMTP服务器的用户密码
 $mailtitle = $_POST['title'];//邮件主题
 $mailcontent = "<h1>".$_POST['content']."</h1>";//邮件内容
 $mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件
 //************************ 配置信息 ****************************
 $smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
 $smtp->debug = false;//是否显示发送的调试信息
 $state = $smtp->sendmail($smtpemailto, $smtpusermail, $mailtitle, $mailcontent, $mailtype);

 echo "<div style='width:300px; margin:36px auto;'>";
 if($state==""){
 echo "对不起,邮件发送失败!请检查邮箱填写是否有误。";
 echo "<a href='index.html'>点此返回</a>";
 exit();
 }
 echo "恭喜!邮件发送成功!!";
 echo "<a href='index.html'>点此返回</a>";
 echo "</div>";
&#63;>

Appreciation of screenshots of the effect:

The method shared in this article is simple and easy to understand, I hope it can help everyone.

The following is the source code download address provided for everyone: php uses the SMTP class to implement email sending

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1066504.htmlTechArticlephp uses the smtp class to send emails. The phpsmtp class email smtp class method of sending emails is simple and stable. You can send emails with just a few simple configurations. Are you looking forward to giving it a try...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn