<?php
require('class/connect.php');
require('class/db_sql.php');
$link=db_connect();
$empire=new mysqlquery();
echo "send start <br />";
include('class/SendEmail.inc.php');
$email="zzjwlby@126.com";//邮件接收者的E-mail
$moshi=2;// 用后台参数 2 用自定义参数
$title='测888试20220416';
$content='您好,希望疫情早点结束!请做好个人防护。';
if($moshi==1){
$sm=EcmsToSendMail($email, $title,$content);//邮件接收者的E-mail, 邮件标题, 邮件正文
}else{
//$pr=$empire->fetch1("select sendmailtype,smtphost,fromemail,loginemail,emailusername,emailpassword,smtpport,emailname from {$dbtbpre}enewspublic limit 1");
/*
[sendmailtype] => 1
[smtphost] => smtp.163.com
[fromemail] => sxoxgs@163.com XGJQGRZERLIRLXKD
[loginemail] => 1
[emailusername] => ***
[emailpassword] => ***
[smtpport] => 465
[emailname] => 在线预约
*/
$pr['sendmailtype']=1;
$pr['smtphost']='smtp.163.com';
$pr['fromemail']='yf90113325@163.com';
$pr['loginemail']=1;
$pr['emailusername']='yf90113325';
$pr['emailpassword']='********';
$pr['smtpport']=465;
$pr['emailname']='在线预约';
//发送初使化
$mailer=FirstSendMail($pr,$title,$content);
if(is_array($email))
{
$count=count($email);
for($i=0;$i<$count;$i++)
{
if($email[$i])
{
$mailer->AddAddress($email[$i]);
}
}
}
else
{
$mailer->AddAddress($email);
}
if(!$mailer->Send())
{
echo '发送失败';
}else{
echo('发送成功');
}
}
echo $mail_test." send over <br />";
db_close();
$empire=null;
?>
然后,打开smtp的错误开关,修改文件e/class/SendEmail.inc.php
public $SMTPDebug = '10';//false;
获取邮箱参数的代码:
$pr=$empire->fetch1("select sendmailtype,smtphost,fromemail,loginemail,emailusername,emailpassword,smtpport,emailname from {$dbtbpre}enewspublic limit 1");
/*
[smtphost] => smtp.163.com
[fromemail] => ***@163.com
[loginemail] => 1
[emailusername] => ****
[emailpassword] => ***
[smtpport] => 465
*/
帝国后台的设置:
访问,linshi.php 就可以看到详细的错误信息。
/*
ERROR: Failed to connect to server: Connection timed out (110)
*/
常见问题:
1. 服务器的安全组要不要放行465端口
2. SMTP -> FROM SERVER:553 Local user only,163 smtp4,HNxpCgCXRbYa8llirSmnBQ--.10006S3 1650061850
3. MTP -> ERROR: MAIL not accepted from server: 550 Invalid User