Home >Backend Development >PHP Tutorial >php uses smtp class to send emails

php uses smtp class to send emails

墨辰丷
墨辰丷Original
2018-06-06 15:01:561286browse

This article mainly introduces PHP to use the SMTP class to send emails. Interested friends can refer to it. I hope it will be helpful to everyone.

The following is the core code:

<?php
 require_once "email.class.php";
 //******************** 配置信息 ********************************
 $smtpserver = "smtp.126.com";//SMTP服务器
 $smtpserverport =25;//SMTP服务器端口
 $smtpusermail = "new2008oh@126.com";//SMTP服务器的用户邮箱
 $smtpemailto = $_POST[&#39;toemail&#39;];//发送给谁
 $smtpuser = "new2008oh";//SMTP服务器的用户帐号
 $smtppass = "您的邮箱密码";//SMTP服务器的用户密码
 $mailtitle = $_POST[&#39;title&#39;];//邮件主题
 $mailcontent = "<h1>".$_POST[&#39;content&#39;]."</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 "<p style=&#39;width:300px; margin:36px auto;&#39;>";
 if($state==""){
 echo "对不起,邮件发送失败!请检查邮箱填写是否有误。";
 echo "<a href=&#39;index.html&#39;>点此返回</a>";
 exit();
 }
 echo "恭喜!邮件发送成功!!";
 echo "<a href=&#39;index.html&#39;>点此返回</a>";
 echo "</p>";
?>

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning.

Related recommendations:

Detailed explanation of class examples for php to generate verification codes, thumbnails and watermarks

PHP implements secure downloading of files Methods and examples

Detailed explanation of common PDO class library examples of PHP

The above is the detailed content of php uses smtp class to send emails. For more information, please follow other related articles on the PHP Chinese website!

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