php一个简单邮箱发送组件介绍

作者:袖梨 2022-06-24
 代码如下 复制代码

include ('class/class.phpmailer.php');

$config = array(
        'host'=>'smtp.163.com',
        'port'=>'25',
        'user'=>'***',
        'passwd'=>'****',
        'from'=>'[email protected]',
        'fromname'=>'郑州',
       
        );
$subject = 'this is a test mail';
$body = '

测试内容
这是内容
';
$address='[email protected]';
$username='本人';

$mail = new PHPMailer();
$mail->CharSet = 'gb2312';
$mail->IsSMTP();
$mail->Host = $config['host'];
$mail->Port = $config['port'];

$mail->From = $config['from'];
$mail->FromName = $config['fromname'];
$mail->SMTPAuth = true;

$mail->Username = $config['user'];
$mail->Password = $config['passwd'];

$mail->Subject=$subject;
$mail->AltBody="text/html";
$mail->MsgHTML($body);


$mail->AddAddress($address,$username);

if(!$mail->Send())
{
    echo "Mail Error :".$mail->ErrorInfo;
}else
{
    echo "恭喜发送成功!";
}

相关文章

精彩推荐