当前位置:Gxlcms > PHP教程 > 使用PHP发送邮件出现这个错误:ThefollowingFromaddressfailed:xxxx@163.com

使用PHP发送邮件出现这个错误:ThefollowingFromaddressfailed:xxxx@163.com

时间:2021-07-01 10:21:17 帮助过:0人阅读

使用了TP框架!以下是源码:
namespace ApiController;

use ThinkController;

class EmailController extends Controller
{
public function test(){

  $msg = pmail('493107977@qq.com','午夜DJ','封装测试','hello world');
  echo $msg;

}

?php>

return array(

//'配置项'=>'配置值'
'TMPL_PARSE_STRING' => array(
    '__ADMIN__' => '/Public/Admin',
    '__COMMON__' => '/Public/Common',
    '__VENDORS__' => '/Public/Venders',
    '__HOME__' => '/Public/Home',
    '__USER__' => '/Public/User',

    '__UP_GOODS__'=>'/Public/Uploads/Goods',
    '__UP_USER__'=>'/Public/Uploads/User'

),

'PMAIL' => array(
    'Host' => 'stmp.163.com',
    'Username' => 'xxxxxx',
    'Password' => 'xxxxxx',
    'From' => 'xxxxx@163.com',
    'FromName' => 'xxxx',
),

);

function pmail($tomail = '',$toname = '',$title = '',$content = ''){

require_once VENDOR_PATH.'PHPMailer/class.phpmailer.php';
// 实例化
$pm = new \PHPMailer();
foreach (C('PMAIL') as $k => $v){
    $pm->$k = $v;
}

// 服务器相关信息
// $pm->Host = 'smtp.163.com'; // SMTP服务器

$pm->IsSMTP(); // 设置使用SMTP服务器发送邮件
$pm->SMTPAuth = true; // 需要SMTP身份认证

// $pm->Username = 'woainigui8888'; // 登录SMTP服务器的用户名
// $pm->Password = '7618387asd'; // 登录SMTP服务器的密码
//
//// 发件人信息
// $pm->From = 'woainigui8888@163.com';
// $pm->FromName = '电音之王';

// 收件人信息

$pm->AddAddress($tomail,$toname); // 添加一个收件人

// 邮件内容

$pm->CharSet = 'utf-8'; // 内容编码
$pm->Subject = $title; // 邮件标题
$pm->MsgHTML($content); // 邮件内容

// $this->AddAttachment($path); // 附件

// 发送邮件

if($pm->Send()){
    return true;
}else {
    return $pm->ErrorInfo;
}

}

使用PHP发送邮件出现这个错误:The following From address failed:xxxx@163.com

回复内容:

使用了TP框架!以下是源码:
namespace ApiController;

use ThinkController;

class EmailController extends Controller
{
public function test(){

  $msg = pmail('493107977@qq.com','午夜DJ','封装测试','hello world');
  echo $msg;

}

?php>

return array(

//'配置项'=>'配置值'
'TMPL_PARSE_STRING' => array(
    '__ADMIN__' => '/Public/Admin',
    '__COMMON__' => '/Public/Common',
    '__VENDORS__' => '/Public/Venders',
    '__HOME__' => '/Public/Home',
    '__USER__' => '/Public/User',

    '__UP_GOODS__'=>'/Public/Uploads/Goods',
    '__UP_USER__'=>'/Public/Uploads/User'

),

'PMAIL' => array(
    'Host' => 'stmp.163.com',
    'Username' => 'xxxxxx',
    'Password' => 'xxxxxx',
    'From' => 'xxxxx@163.com',
    'FromName' => 'xxxx',
),

);

function pmail($tomail = '',$toname = '',$title = '',$content = ''){

require_once VENDOR_PATH.'PHPMailer/class.phpmailer.php';
// 实例化
$pm = new \PHPMailer();
foreach (C('PMAIL') as $k => $v){
    $pm->$k = $v;
}

// 服务器相关信息
// $pm->Host = 'smtp.163.com'; // SMTP服务器

$pm->IsSMTP(); // 设置使用SMTP服务器发送邮件
$pm->SMTPAuth = true; // 需要SMTP身份认证

// $pm->Username = 'woainigui8888'; // 登录SMTP服务器的用户名
// $pm->Password = '7618387asd'; // 登录SMTP服务器的密码
//
//// 发件人信息
// $pm->From = 'woainigui8888@163.com';
// $pm->FromName = '电音之王';

// 收件人信息

$pm->AddAddress($tomail,$toname); // 添加一个收件人

// 邮件内容

$pm->CharSet = 'utf-8'; // 内容编码
$pm->Subject = $title; // 邮件标题
$pm->MsgHTML($content); // 邮件内容

// $this->AddAttachment($path); // 附件

// 发送邮件

if($pm->Send()){
    return true;
}else {
    return $pm->ErrorInfo;
}

}

使用PHP发送邮件出现这个错误:The following From address failed:xxxx@163.com

人气教程排行