PHPMailer 本机不需要安装SMTP Server就能发邮件

本文介绍如何使用PHPMailer库从163邮箱向Gmail发送带有附件的HTML格式邮件。通过简单的代码示例展示了配置SMTP服务器、设置邮件内容及附件等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PHP自带的函数mail()不能满足大家的需要,于是便有了phpmailer,有了它操作邮件就简单多了,使用它自带的class可以收发自如.下面是我使用的自己的163邮箱发送到自己的gmail邮箱的代码

<?php

//error_reporting(E_ALL);
error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');
//date_default_timezone_set(date_default_timezone_get());

include_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail = new PHPMailer();

$body = $mail->getFile('contents.html');
$body = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth=true;
$mail->Host = "smtp.163.com"; // SMTP server
$mail->Username = "bubble1000";
$mail->Password = "密码不能写哦";

$mail->From = "bubble1000@163.com";
$mail->FromName = "First Last";

$mail->Subject = "PHPMailer Test Subject via smtp";

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$mail->AddAddress("luzaolai@gmail.com", "John Doe");

$mail->AddAttachment("images/phpmailer.gif"); // attachment

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

?>



这段代码是我根据其中的test_smtp.php改的.附件是phpmailer的zip文件,或者可以到sourceforge.net上搜搜. :) ,会有新发现的哦!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值