Rumah >pembangunan bahagian belakang >tutorial php >使用PHP发送邮件出现这个错误:The following From address failed:xxxx@163.com
使用了TP框架!以下是源码:
namespace ApiController;
use ThinkController;
class EmailController extends Controller
{
public function test(){
<code> $msg = pmail('493107977@qq.com','午夜DJ','封装测试','hello world'); echo $msg;</code>
}
return array(
<code>//'配置项'=>'配置值' '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', ), </code>
function pmail($tomail = '',$toname = '',$title = '',$content = ''){
<code>require_once VENDOR_PATH.'PHPMailer/class.phpmailer.php'; // 实例化 $pm = new \PHPMailer(); foreach (C('PMAIL') as $k => $v){ $pm->$k = $v; }</code>
// 服务器相关信息
// $pm->Host = 'smtp.163.com'; // SMTP服务器
<code>$pm->IsSMTP(); // 设置使用SMTP服务器发送邮件 $pm->SMTPAuth = true; // 需要SMTP身份认证</code>
// $pm->Username = 'woainigui8888'; // 登录SMTP服务器的用户名
// $pm->Password = '7618387asd'; // 登录SMTP服务器的密码
//
//// 发件人信息
// $pm->From = 'woainigui8888@163.com';
// $pm->FromName = '电音之王';
// 收件人信息
<code>$pm->AddAddress($tomail,$toname); // 添加一个收件人 </code>
// 邮件内容
<code>$pm->CharSet = 'utf-8'; // 内容编码 $pm->Subject = $title; // 邮件标题 $pm->MsgHTML($content); // 邮件内容</code>
// $this->AddAttachment($path); // 附件
// 发送邮件
<code>if($pm->Send()){ return true; }else { return $pm->ErrorInfo; }</code>
使用PHP发送邮件出现这个错误:The following From address failed:xxxx@163.com
使用了TP框架!以下是源码:
namespace ApiController;
use ThinkController;
class EmailController extends Controller
{
public function test(){
<code> $msg = pmail('493107977@qq.com','午夜DJ','封装测试','hello world'); echo $msg;</code>
}
return array(
<code>//'配置项'=>'配置值' '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', ), </code>
function pmail($tomail = '',$toname = '',$title = '',$content = ''){
<code>require_once VENDOR_PATH.'PHPMailer/class.phpmailer.php'; // 实例化 $pm = new \PHPMailer(); foreach (C('PMAIL') as $k => $v){ $pm->$k = $v; }</code>
// 服务器相关信息
// $pm->Host = 'smtp.163.com'; // SMTP服务器
<code>$pm->IsSMTP(); // 设置使用SMTP服务器发送邮件 $pm->SMTPAuth = true; // 需要SMTP身份认证</code>
// $pm->Username = 'woainigui8888'; // 登录SMTP服务器的用户名
// $pm->Password = '7618387asd'; // 登录SMTP服务器的密码
//
//// 发件人信息
// $pm->From = 'woainigui8888@163.com';
// $pm->FromName = '电音之王';
// 收件人信息
<code>$pm->AddAddress($tomail,$toname); // 添加一个收件人 </code>
// 邮件内容
<code>$pm->CharSet = 'utf-8'; // 内容编码 $pm->Subject = $title; // 邮件标题 $pm->MsgHTML($content); // 邮件内容</code>
// $this->AddAttachment($path); // 附件
// 发送邮件
<code>if($pm->Send()){ return true; }else { return $pm->ErrorInfo; }</code>
使用PHP发送邮件出现这个错误:The following From address failed:xxxx@163.com