Basic Example using SMTP (for PHPMailer v5.0.0 and up)
2024-09-01 10:20:17
sample as below:
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded $mail = new PHPMailer(); $body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body); $mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->Username = "yourname@yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password $mail->SetFrom('name@yourdomain.com', 'First Last'); $mail->AddReplyTo("name@yourdomain.com","First Last"); $mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe"); $mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
最新文章
- BIT 树状数组 详解 及 例题
- JavaScript中数组去除重复
- Android应用开发-数据存储和界面展现(一)(重制版)
- [置顶] 两台一级域名相同二级域名不同的服务器,怎么共享session
- Yii2 富头像上传
- MVC 分页获取数据 及点选按钮
- CC++初学者编程教程(11) 配置Windows数据库服务器
- python函数abs()
- [转]View属性 之 paddingStart &; paddingEnd
- &;#65279导致网页顶部空白一行的解决办法【实测有效】
- python 逻辑运算符问题
- KO ----- 静态资源404问题
- C代码快速构建框架
- 【python001-IDLE】
- Bootstarp 模版网站
- 1-100求和 sum(range(101))
- Hive,HANA可视化客户端工具
- win 10 文件夹 背景 没效果
- 《转》深入理解Activity启动流程(三)–Activity启动的详细流程2
- 【BZOJ1494】【NOI2007】生成树计数(动态规划,矩阵快速幂)
热门文章
- ThreadPoolExecutor执行任务,异常日志缺失问题
- 2019 ICPC南京网络预选赛 I Washing clothes 李超线段树
- HDU - 4305 - Lightning 生成树计数 + 叉积判断三点共线
- 拿 C# 搞函数式编程 - 1
- 【LeetCode】103# 二叉树的锯齿形层次遍历
- Java IO写文件效率
- [1]尝试用Unity3d制作一个王者荣耀(持续更新)->;AssetBundle管理器
- FreeSql (四)实体特性 Fluent Api
- Zookeeper系列一:Zookeeper基础命令操作
- .Net基础篇_学习笔记_第八天_复杂数据类型(常量/枚举/结构)