0

I have a problem with phpmailer.

<?php
  require 'PHPMailer/Exception.php';
  require 'PHPMailer/PHPMailer.php';
  require 'PHPMailer/SMTP.php';
  use PHPMailer\PHPMailer\PHPMailer;
  use PHPMailer\PHPMailer\SMTP;
  use PHPMailer\PHPMailer\Exception;
  $mail = new PHPMailer(true);

  try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                  
    // $mail->isSMTP();                                           
    $mail->Host       = 'smtp.google.com';                    
    $mail->SMTPAuth   = true;                                 
    $mail->SMTPAuthTLS   = true;                              
    $mail->Username   = 'myemail';                
    $mail->Password   = 'mypassword';                              
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //PHPMailer::ENCRYPTION_SMTPS;  
    $mail->Port       = 587;                

    //Recipients
    $mail->setFrom('hismail', 'Joe');
    $mail->addAddress('mymail', 'OsamaMohammed');
    $mail->addReplyTo("hismail");

    //Content
    $mail->isHTML(true);                                  //Set email format to HTML
    $mail->Subject = 'Mail verify';
    $mail->Body    = 'Thanks for siging in! Your code is 179012';

    $mail->SendMail = "mymail";
    // $mail->SendMail = "/usr/sbin/sendmail";
    $mail->send();
    echo 'Message has been sent';
    } catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
  }.

It shows me:

Sending with mail()
Sendmail path: /usr/sbin/sendmail
Envelope sender: hismail
To: OsamaMohammed mymail
Subject: Mail verify
Headers: Date: Fri, 2 Jun 2023 17:34:29 +0200From: OsamaMohammed <hismail> Reply-To: <hismail> .comMessage-ID: <ID> X-Mailer: PHPMailer 6.8.0 (https://github.com/PHPMailer/PHPMailer)MIME-Version: 1.0Content-Type: text/html; charset=iso-8859-1
Additional params: -fhismail
Result: true
Message has been sent. 

Keep in mind that i have commented $mail->isSTMP() because it doesn't connect to the STMP host.

I tried commenting $mail->STMP, but it doesn't work. I tried changing the ssl options, and I couldn't. Finally, I was trying using openssl, but I sent this question first.

user1191247
  • 10,808
  • 2
  • 22
  • 32
  • Sending mail is a very complex process to troubleshoot. Read the duplicate question, but at this point, I'd start checking the sendmail logs on your server. – aynber Jun 02 '23 at 15:56
  • Why did you remove `$mail->isSMTP();` as you are trying to use a SMTP Server, that causes PHPMailers to be a SMTP Client, which I would have thought you would need to be – RiggsFolly Jun 02 '23 at 15:57
  • If you comment `$mail->isSMTP();` then apparently PHPMailer uses the php `mail()` to send mail. That does no checking, just throws it up the line to a mail server – RiggsFolly Jun 02 '23 at 15:58
  • And as you are using `smtp.google.com` as the host, you need to use `$mail->isSMTP();` – RiggsFolly Jun 02 '23 at 15:59
  • This may be a relevant read, or even a DUP https://stackoverflow.com/questions/39029466/what-is-the-difference-between-ismail-and-issmtp – RiggsFolly Jun 02 '23 at 16:00
  • @RiggsFolly I commented `$mail->isSMTP()`, because there was an error called: `Mailer error. SMTP error. Failed to connect the host` – Osama Mohammed Jun 02 '23 at 16:57
  • @RiggsFolly. Also I heard that the problem is because of spam folder, but I don't know how to solve that. – Osama Mohammed Jun 02 '23 at 17:00

0 Answers0