// 开启php_openssl以及php_sockets
<?php/** * created by phpstorm. * date: 2018/4/23 * time: 23:14 */namespace app\common\sendingpay;use \think\controller;use app\common\phpmailer\phpmailer;/** * 发送邮件确认支付 * */class sendingpay extends controller{ function __construct() { parent::__construct(); } public function trigger($totalamount, $ordernum) { $body = '订单支金额'.$totalamount.',订单id(ordernum)'.$ordernum; $this->sendmail('j.@foxmail.com', $body); } public function sendmail($toemail = '', $body = '') { // 开启php_openssl以及php_sockets $sendmail = 'j.c@foxmail.com'; //发件人邮箱 $sendmailpswd = "jvqdkdyhswg"; //客户端授权密码,而不是邮箱的登录密码! $send_name = 'lxx';// 设置发件人信息,如邮件格式说明中的发件人, $toemail = 'j.c@foxmail.com';//定义收件人的邮箱 $to_name = 'lxxback';//设置收件人信息,如邮件格式说明中的收件人 $mail = new phpmailer(); $mail->smtpdebug = 1; $mail->issmtp();// 使用smtp服务 $mail->charset = "utf8";// 编码格式为utf8,不设置编码的话,中文会出现乱码 $mail->host = "smtp.qq.com";// 发送方的smtp服务器地址 $mail->smtpauth = true;// 是否使用身份验证 $mail->username = $sendmail;//// 发送方的 $mail->password = $sendmailpswd;//客户端授权密码,而不是邮箱的登录密码! $mail->smtpsecure = "ssl";// 使用ssl协议方式 $mail->port = 465;// qq端口465或587) $mail->ishtml(true); $mail->setfrom($sendmail, $send_name);// 设置发件人信息,如邮件格式说明中的发件人, $mail->addaddress($toemail, $to_name);// 设置收件人信息,如邮件格式说明中的收件人, $mail->addreplyto($sendmail, $send_name);// 设置回复人信息,指的是收件人收到邮件后,如果要回复,回复邮件将发送到的邮箱地址 //$mail->addcc("xxx@qq.com");// 设置邮件抄送人,可以只写地址,上述的设置也可以只写地址(这个人也能收到邮件) //$mail->addbcc("xxx@qq.com");// 设置秘密抄送人(这个人也能收到邮件) //$mail->addattachment("bug0.jpg");// 添加附件 $mail->subject = "订单支付确认";// 邮件标题 $mail->body = $body;// 邮件正文 //$mail->altbody = "this is the plain text纯文本";// 这个是设置纯文本方式显示的正文内容,如果不支持html方式,就会用到这个,基本无用 if (!$mail->send()) {// 发送邮件 //echo "mailer error: ".$mail->errorinfo;// 输出错误信息 return -1; } else { return 1; } } }
下载的源文件命名空间namespace app\common\phpmailer;
相关推荐:
phpmailer实现php发邮件功能
php使用phpmailer发送邮件的方法分享
以上就是使用 phpmailer 配合 qq邮箱 发送邮件 的详细内容。
