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;
}
}
网友评论