美文网首页
PHPmailer发送邮件

PHPmailer发送邮件

作者: 九夜ailing | 来源:发表于2019-05-05 23:25 被阅读0次
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;
        }
    }

相关文章

网友评论

      本文标题:PHPmailer发送邮件

      本文链接:https://www.haomeiwen.com/subject/xfeqvqtx.html