Search code examples
phpmailerlaravel-7

Mail sending using PHP Mailer in Laravel 7


I am using PHPMailer in Laravel 7. Mail works fine. Send Email successful. But after click 'send' button it shows some line about server after this, showing the success message.

This lines are show -

2021-01-04 19:27:49 SERVER -> CLIENT: xxxx
2021-01-04 19:27:49 CLIENT -> SERVER: 
2021-01-04 19:27:49 SERVER -> CLIENT: 
2021-01-04 19:27:49 SERVER -> CLIENT: xxxxx
2021-01-04 19:27:49 CLIENT -> SERVER: xxxx
2021-01-04 19:27:49 SERVER -> CLIENT: xxxx

My Controller Code :

 public function jobApply(Request $request)
    {
        $resume = Resume::where('candidate_id', Auth::guard('candidate')->user()->id)->first();
        $compEmail = $request->txt_compEmail;
        $cadEmail = $request->txt_candEmail;
        $subject = $request->txt_subject;
        $body = $request->txt_candSalary;
        $file = $resume->resume;
        $mail = new PHPMailer(true);
        try {
            //Server settings
            $mail->SMTPDebug = SMTP::DEBUG_SERVER;
            $mail->isSMTP();
           // Send using SMTP
            $mail->Host       = env('MAIL_HOST'); 
            // Set the SMTP server to send through
            $mail->SMTPAuth   = true;
            // Enable SMTP authentication
            $mail->Username   = env('MAIL_USERNAME');
            // SMTP username
            $mail->Password   = env('MAIL_PASSWORD');
           // SMTP password
            $mail->SMTPSecure = env('MAIL_ENCRYPTION');
            // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
            $mail->Port       = env('MAIL_PORT');
            Log::info("Check:".$mail->Host. ' '.$mail->Username.' '.$mail->Password.' '.$mail->SMTPSecure.' '.$mail->Port);// TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above

            //Recipients
            $mail->setFrom($cadEmail);
            $mail->addAddress($compEmail);
           // Add a recipient
            $mail->AltBody ='';
            $mail->addAttachment($file );
            // Content
            $mail->isHTML(true);
            // Set email format to HTML
            $mail->Subject = $subject;
            $mail->Body    = 'Expected Salary : ' . $body ;
            $mail->send();
        }  catch (Exception $e) {
            echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
//            dd($e);
        }
        if ($mail){
            return redirect()->back()->with('success','Mail Send Successfully..!!');
        }
        else{
            return redirect()->back()->with('error','Something Went Wrong')->withInput();
        }
    }

How Can I hide this ? Anyone suggest me any solution. Advanced thanks.


Solution

  • You've asked it to show debug output, so it is producing it. If you don't want that, don't turn it on – comment out this line:

    $mail->SMTPDebug = SMTP::DEBUG_SERVER;