Home >Backend Development >PHP Tutorial >This error occurs when sending emails using PHP: The following From address failed:xxxx@163.com

This error occurs when sending emails using PHP: The following From address failed:xxxx@163.com

WBOY
WBOYOriginal
2016-10-11 14:23:467979browse

Using TP framework! The following is the source code:
namespace ApiController;

use ThinkController;

class EmailController extends Controller
{
public function test(){

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

}

?php>

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',
),

</p>
<h1>);</h1>
<p><?php<br>function pmail($tomail = '',$toname = '',$title = '',$content = ''){</p>
<pre class="brush:php;toolbar:false"><code>require_once VENDOR_PATH.'PHPMailer/class.phpmailer.php';
// 实例化
$pm = new \PHPMailer();
foreach (C('PMAIL') as $k => $v){
    $pm->$k = $v;
}
</p>
<p>// Server related information<br>// $pm->Host = 'smtp.163.com'; // SMTP server</p>
<pre class="brush:php;toolbar:false"><code>$pm->IsSMTP(); // 设置使用SMTP服务器发送邮件
$pm->SMTPAuth = true; // 需要SMTP身份认证</code>

// $pm->Username = 'woainigui8888'; // Username to log in to the SMTP server
// $pm->Password = '7618387asd'; // Password to log in to the SMTP server
//
/// / Sender information
// $pm->From = 'woainigui8888@163.com';
// $pm->FromName = 'The King of Electronic Music';

//Recipient information

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

// Email content

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

// $this->AddAttachment($path); // Attachment

//Send email

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

}

This error occurs when sending emails using PHP: The following From address failed:xxxx@163.com

Reply content:

Using TP framework! The following is the source code:
namespace ApiController;

use ThinkController;

class EmailController extends Controller
{
public function test(){

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

}

?php>

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',
),

</p>
<h1>);</h1>
<p><?php<br>function pmail($tomail = '',$toname = '',$title = '',$content = ''){</p>
<pre class="brush:php;toolbar:false"><code>require_once VENDOR_PATH.'PHPMailer/class.phpmailer.php';
// 实例化
$pm = new \PHPMailer();
foreach (C('PMAIL') as $k => $v){
    $pm->$k = $v;
}
</p>
<p>// Server related information<br>// $pm->Host = 'smtp.163.com'; // SMTP server</p>
<pre class="brush:php;toolbar:false"><code>$pm->IsSMTP(); // 设置使用SMTP服务器发送邮件
$pm->SMTPAuth = true; // 需要SMTP身份认证</code>

// $pm->Username = 'woainigui8888'; // Username to log in to the SMTP server
// $pm->Password = '7618387asd'; // Password to log in to the SMTP server
//
/// / Sender information
// $pm->From = 'woainigui8888@163.com';
// $pm->FromName = 'The King of Electronic Music';

//Recipient information

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

// Email content

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

// $this->AddAttachment($path); // Attachment

//Send email

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

}

This error occurs when sending emails using PHP: The following From address failed:xxxx@163.com

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