您的位置 首页 php

PHPmailer发送邮件

<?php
/**
 * 安装 composer require phpmailer/phpmailer
 * 
 */
 
 public static function sendEmail($parmas)
 {
 $mail = new PHPMailer(true);
 $getMsg = $parmas['email'];
 try {
 //Server settings
 $mail->CharSet = 'UTF-8';
 $mail->SMTPDebug = 2; // Enable verbose debug output
 $mail->isSMTP(); // Set mailer to use SMTP
 $mail->Host = 'smtp.qq.com'; // Specify main and backup SMTP servers
 $mail->SMTPAuth = true; // Enable SMTP authentication
 $mail->Username = '2323@qq.com'; // SMTP username
 $mail->Password = '2323232'; // SMTP password
 $mail->SMTPSecure = ' ssl '; // Enable TLS encryption, `ssl` also accepted
 $mail->Port = 465; // TCP port to connect to
 //Recipients
 $mail->setFrom('206989662@qq.com', 'dh');
// $mail->addAddress('1066179972@qq.com', 'Joe User'); // Add a recipient
 $mail->addAddress($getMsg); // Name is optional
// $mail->addReplyTo('info@example.com', 'Information');
// $mail->addCC('cc@example.com');
// $mail->addBCC('bcc@example.com');
 // Attachments
// $mail->addAttachment('/ var / tmp /file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image. jpg ', 'new.jpg'); // Optional name
 // Content
 $mail->is html (true); // Set email format to HTML
 $mail-> Subject  = 'Here is the subject';
 $mail->Body = <<<html
 This is the HTML message body <b>in bold!</b>
html;
 $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
 $mail->send();
 echo 'Message has been sent';
 exit;
 } catch ( Exception  $e) {
 echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
 exit;
 }
 }
 

文章来源:智云一二三科技

文章标题:PHPmailer发送邮件

文章地址:https://www.zhihuclub.com/150958.shtml

关于作者: 智云科技

热门文章

网站地图