PHPmailer发送邮件

1670108266a3184e255f1f2ebe78ae4034fa9d94.jpg

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('test@qq.com', 'test');
//            $mail->addAddress('test@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->isHTML(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;
        }
    }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容