欢迎光临
感谢一路有你

laravel 使用PHPmailer扩展

如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
 
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('ellen@example.com');               // 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    = 'This is the HTML message body <b>in bold!</b>';
   		    $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) 打赏
未经允许不得转载:王明昌博客 » laravel 使用PHPmailer扩展
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏