How can I send an email via PHPMAILER without SSL - port 25?
Asked Answered
T

2

6

I want to send an email without SSL using PHPMailer. I have enabled the debug mode so that I can check the details in the logs.

    $mail = new PHPMailer\PHPMailer\PHPMailer();
    $mail->IsSMTP(true); // enable SMTP
    $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true; // authentication enabled
    $mail->SMTPSecure = false; // secure transfer enabled REQUIRED for Gmail
    $mail->Host = "mail.company.co.uk";
    $mail->Port = 25; // or 587
    $mail->IsHTML(true);
    $mail->Username = "[email protected]";
    $mail->Password = "password_of_username";
    $mail->SetFrom($email,$name);
    $mail->Subject = $subject;
    $mail->Body = $message;
    $mail->AddAddress($to);

This is giving an exception:

2018-09-28 10:04:27 CLIENT -&gt; SERVER: EHLO localhost<br>
2018-09-28 10:04:27 CLIENT -&gt; SERVER: STARTTLS<br>
SMTP Error: Could not connect to SMTP host.<br>
2018-09-28 10:04:28 CLIENT -&gt; SERVER: QUIT<br>
2018-09-28 10:04:28 <br>
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting<br>
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Tar answered 28/9, 2018 at 10:6 Comment(0)
N
21

You've based your code on an old example, which doesn't help. You can't see what's going on because you've only used 1 for SMTPDebug; set it to 2.

Your mail server is advertising that it supports STARTTLS on port 25, so PHPMailer is using it automatically. You can disable encryption entirely by doing this:

$mail->SMTPAutoTLS = false;
$mail->SMTPSecure = false;

However, I'd recommend not doing this; fix your TLS config instead. You probably need to update your local CA certificate bundle - see the troubleshooting guide for more details.

One time that doing this is appropriate is when you are sending to localhost; you can't get a certificate for localhost, but there is no security risk as it's all local, so disabling TLS is fine. Of course, your mail server should not be advertising that it supports STARTTLS on localhost, but that's a separate problem!

Neurogram answered 28/9, 2018 at 10:36 Comment(2)
$mail->SMTPAutoTLS = false; <--- this did the job. SSL one was working fine till if fix the SSL issue. I want to keep the email form going.Tar
I read your comments on a number of web pages. Thanks for the helpTar
B
0

You can try this: $mail->SMTPAuth = false;

Brost answered 29/11, 2022 at 16:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.