1

Below is the phpmailer code which I am using :

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    require '../vendor/autoload.php'; 
    $mail = new PHPMailer(true);  
    try { 
     $mail->SMTPDebug = 2; 
     $mail->isSMTP();
     $mail->Host = as given in the configure mail client window; 
     $mail->SMTPAuth = true; 
     $mail->Username =as given in the configure mail client window; 
     $mail->Password = as given in the configure mail client window;  
     $mail->SMTPSecure = 'tls' ;
     $mail->Port = 465; 
     $mail->setFrom('my email', 'my name'); 
     $mail->addAddress('email', 'name');
     $mail->isHTML(true);
     $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;
     }

The page keeps loading and the e-mail is not sent,What is happening ? and how should I configure this . I am using godaddy cpanel.

  • Turn on debugging for PHPMailer to see what's actually going on: https://github.com/PHPMailer/PHPMailer/wiki/SMTP-Debugging – WillardSolutions May 22 '18 at 19:58
  • 1
    I have experienced similar issues in the past - I believe the problem is not with your code but rather your hosting provider. To fix this, you could try sending your email messages from another server such as Gmail's SMTP servers: https://stackoverflow.com/questions/16048347/send-email-using-gmail-smtp-server-through-php-mailer – Daniel Arthur May 22 '18 at 19:58
  • 2
    PHPMailer doesn't actually *send* emails, it just puts them into a queue to be sent by the host. The speed at which delivery happens depends on many things, almost all of which are out of your control. – Alex Howansky May 22 '18 at 20:07
  • Er wait -- are you talking about the amount of time it takes for this script to run? Or the amount of time it takes for the recipient to receive the message? – Alex Howansky May 22 '18 at 20:18
  • @AlexHowansky the amount of time it takes for the recipient to receive the message – Suvansh Rana May 23 '18 at 04:27
  • Right OK, that is (for the most part) out of your control. – Alex Howansky May 23 '18 at 04:52
  • PHPMailer does/can send messages directly, it’s just usually not the most efficient way, but it’s the only way if you have no local mail server. Indeed I did understand that it was the submission time that was the problem. – Synchro May 23 '18 at 06:13

1 Answers1

0

You're using SMTP to localhost (which is the recommended and usually the fastest sending mechanism, as far as your script is concerned), but you've enabled encryption and authentication, so your local mail server will need to present a valid certificate for localhost, which is not going to happen. It's usually unnecessary to use encryption or authentication when sending to localhost, because you can whitelist localhost as the source, and this will make it even faster.

If you set SMTPDebug = 2, you can look at the timestamps in the SMTP conversation and see which part is taking a long time.

Keepalive won't help unless you're sending lots of messages in quick succession.

It may also help to look in your local mail server's logs and see if there's anything interesting in there.

You're also using a very old version of PHPMailer; get the latest, and base your code on the examples provided.

You should have no trouble submitting a few hundred messages per second.

If your problem is that submission is fast, but ultimate delivery is slow, you need to look at your local mail server logs for why that is. You may be getting delivery deferrals.

Synchro
  • 35,538
  • 15
  • 81
  • 104
  • So do I need to remove the SMTPAuth and SMTPSecure ? – Suvansh Rana May 23 '18 at 04:31
  • Synchro thought you were asking about the time it takes for the script to run. Removing auth and encryption will have no effect on delivery speed. – Alex Howansky May 23 '18 at 04:57
  • For installation of PHPMailer 6.0.5 do I have to just download and place the files in the directory or use composer ? – Suvansh Rana May 23 '18 at 04:58
  • @Synchro I have downloaded the phpmailer for my cpanel it is in my root\vendor\phpmailer\phpmailer now how will the following lines differ for me: use PHPMailer/Phpmailer/PHPMailer use PHPmailer/Phpmailer/Exception ? – Suvansh Rana May 23 '18 at 13:39
  • It won’t differ. Those are namespace aliases, not paths. – Synchro May 23 '18 at 19:23