簡體   English   中英

PHP Mailer 在 LARAVEL 中有 SMTP connect()

[英]PHP Mailer having SMTP connect() 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*/
    }

我收到錯誤

SMTP 連接()失敗。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

我不知道誰來解決這個問題。 有人可以幫助我嗎?

我不知道你為什么使用 phpmailer 而不是 swiftmailer(默認情況下)Laravel 的郵件驅動程序。 您可以查看Laravel 郵件

只有您需要更改郵件設置 .env 文件或我建議使用Mailtrap

評論或刪除這個

$mail->isSMTP();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM