简体   繁体   English

PHP Mailer 在 LARAVEL 中有 SMTP connect()

[英]PHP Mailer having SMTP connect() in LARAVEL

This is the structure for PHP MAILER that I´m using in LARAVEL.这是我在 LARAVEL 中使用的 PHP MAILER 结构。

$mail = new PHPMailer;

$mail->isSMTP();                            // Set mailer to use SMTP
$mail->SMTPAuth = true;                     // Enable SMTP authentication
$mail->Username = 'xx@gmail.com';          // SMTP username
$mail->Password = 'xxxx'; // SMTP password
$mail->Host = 'smtp.gmail.com';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->setFrom('info@example.com', 'CodexWorld');
$mail->addReplyTo('info@example.com', 'CodexWorld');
$mail->addAddress('john@gmail.com');   // Add a recipient
$mail->addAddress($data['email']);   // Add a recipient
$mail->isHTML(true);  // Set email format to HTML

$message = '

  <p>HELLO</p>

';

$mail->msgHTML($message);

try {
    if(!$mail->send())
    {
         echo  $mail->ErrorInfo;
    } else {
       /*redirect*/
    }

I´m getting the error我收到错误

SMTP connect() failed. SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

I don't know who to fix this problem.我不知道谁来解决这个问题。 Can anybody could help me?有人可以帮助我吗?

I don't know why are you using phpmailer instead of swiftmailer(which by default) mail driver of Laravel.我不知道你为什么使用 phpmailer 而不是 swiftmailer(默认情况下)Laravel 的邮件驱动程序。 You can check on Laravel Mail您可以查看Laravel 邮件

Only you need to change mail setting .env file or I suggest uses Mailtrap只有您需要更改邮件设置 .env 文件或我建议使用Mailtrap

评论或删除这个

$mail->isSMTP();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM