限时免费试用:欢迎注册 api.bigmodel.org ,快速体验大模型 API 接入服务。
当前位置:首页 >开发者 >网站框架 >后端框架 >Laravel

laravel 使用PHPmailer扩展

分类:Laravel时间:2019-01-12浏览:2514
composer require phpmailer/phpmailer
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
public function test(){
   		// echo "ceshi";
   		$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
   		try {
   		    //Server settings
   		    $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 = '******@qq.com';                 // SMTP username
   		    $mail->Password = '*********';                           // SMTP password
   		    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
   		    $mail->Port = 587;                                    // TCP port to connect to

   		    //Recipients收件人
   		    $mail->setFrom('*******@qq.com', 'Mailer');//发件人
   		    $mail->addAddress('***@qq.com', 'Joe User');     // Add a recipient收件人
   		    // $mail->addAddress('[email protected]');               // Name is optional可选
   		    // $mail->addReplyTo('[email protected]', 'Information');
   		    // $mail->addCC('[email protected]');
   		    // $mail->addBCC('[email protected]');

   		    //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    = 'This is the HTML message body in bold!';
   		    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

   		    $mail->send();
   		    echo 'Message has been sent';
   		} catch (Exception $e) {
   		    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
   		}
   	}
本站文章如未注明出处均为原创,转载请注明出处,如有侵权请邮件联系站长。
0/500
Share your thoughts respectfully.