phpMailer功能强大,使用起来却极其简单,在你安装完lnmp后,按照下面的步骤走即可:
1.下载phpMailer phpMailer_v2.3
2.class.phpmailer.php class.smtp.php这两个文件复制到你的php目录下
3.在你的php目录创建sendemail.php 内容如下即可:
require_once(“class.phpmailer.php”); //phpmailer库
mail = new PHPMailer(); //实例化mail->IsSMTP(); // 启用SMTP
mail->Host = “smtp.exmail.qq.com”; //SMTP服务器 以qq企业邮箱为例子mail->Port = 25; //邮件发送端口
mail->SMTPAuth = true; //启用SMTP认证mail->CharSet = “UTF-8”; //字符集
mail->Encoding = “base64”; //编码方式mail->Username = “[email protected]”; //你的邮箱
mail->Password = “xxxxx”; //你的密码mail->Subject = “找回密码”; //邮件标题mail->From = “[email protected]”; //发件人地址(也就是你的邮箱)mail->FromName = “APP Server”; //发件人姓名
address =data_json->email;//收件人email ,这里是安卓APP提交过来的
mail->AddAddress(address, “”);//添加收件人(地址,昵称(可选))mail->IsHTML(true); //支持html格式内容mail->Body = ‘您好,您的密码是:’.rowdata[0]; //邮件主体内容
//发送
if(!mail->Send()) {
// fail
response[“action”] = “getpwd”;response[“errorid”] = 704;
response[“message”] = “Send Email Error: “.mail->ErrorInfo;
print(json_encode(response));
} else {response[“action”] = “getpwd”;
response[“errorid”] = 0;
print(json_encode(response));
}