PHPMailer not working

Hello support I’ve setup PHPMailer on my site but does not send messages. it works in local host but not on my live site. it also does not output any error messages to help me troubleshoot. The first version I used was 6.0 but noticed the PHP on the web host was 7.0 which is not compatible, so I downgraded to 5.2. but still not working. Kindly assist.

Hi
you can also enable debug mode SMTP Debugging · PHPMailer/PHPMailer Wiki · GitHub

check your website through the browser console (plus refresh) if error 500 appear
https://infinityfree.net/support/http-error-500/

Which transport do you use in PHPmailer? It can be configured to either use PHP mail (which is severely restricted) or use SMTP. Please make sure that you’re actually using SMTP, not PHP mail, to send the messages.

please It uses SMTP to send mail

<?php require ‘PHPMailerAutoload.php’; $mail = new PHPMailer; //$mail->SMTPDebug = 3; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = ‘smtp.yandex.com’; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = ‘[email protected]’; // SMTP username $mail->Password = ‘xxxxxxxxxxxxxx’; // SMTP password $mail->SMTPSecure = ‘ssl’; // Enable TLS encryption, ssl also accepted $mail->Port = 993; // TCP port to connect to $errorMSG = “”; // NAME $name = $_POST[“name”]; $email = $_POST[“email”]; $msg_subject = $_POST[“msg_subject”]; $message = $_POST[“message”]; //Recipients $mail->setFrom($email, $name); $mail->addAddress(‘[email protected]’, ‘Raven IT Solutions’); // Add a recipient $mail->Subject = $msg_subject; $mail->isHTML(TRUE); $mail->Body = $message; $mail->AltBody = $message; if(!$mail->send()) { //echo ‘Message could not be sent.’; //echo 'Mailer Error: ’ . $mail->ErrorInfo; } else { //echo ‘Message has been sent’; }

There is no such error OxyDac

it’s hard for me to read your code because I do not know what is a comment and what is a code,
but never mind…we need a debug log

for the port try 465 or 587

and wait for admin - so that he sees your (the right) code and if is correct

I’ll repost the code again sorry @Oxy

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->SMTPDebug = 2;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.yandex.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '[email protected]';                 // SMTP username
    $mail->Password = 'examplexxxxx';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

$errorMSG = "";

    // NAME
   $name = $_POST["name"];
   $email = $_POST["email"];
   $msg_subject = $_POST["msg_subject"];
   $message = $_POST["message"];


   //Recipients
$mail->setFrom($email, $name);
$mail->addAddress('[email protected]', 'Raven IT Solutions');     // Add a recipient
$mail->Subject = $msg_subject;
$mail->isHTML(TRUE);
$mail->Body = $message;
$mail->AltBody = $message;

if(!$mail->send()) {
    //echo 'Message could not be sent.';
    //echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    //echo 'Message has been sent';
}

delete these comments characters

image

Hello please am currently receiving this error.

2019-03-30 18:54:49 SMTP ERROR: Failed to connect to server: (0)&lt;br&gt; SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting&lt;br&gt;

Hello @Admin,
below is a new error am receiving. I’m awaiting your assistance. Thank you.

2019-03-30 20:09:30 Connection: opening to ssl://smtp.yandex.com:587, timeout=300, options=array ()&lt;br&gt; 2019-03-30 20:09:30 Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol [/home/vol3_4/epizy.com/epiz_21860621/htdocs/PHPMailer/class.smtp.php line 298]&lt;br&gt; 2019-03-30 20:09:30 Connection failed. Error #2: stream_socket_client(): Failed to enable crypto [/home/vol3_4/epizy.com/epiz_21860621/htdocs/PHPMailer/class.smtp.php line 298]&lt;br&gt; 2019-03-30 20:09:30 Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.yandex.com:587 (Unknown error) [/home/vol3_4/epizy.com/epiz_21860621/htdocs/PHPMailer/class.smtp.php line 298]&lt;br&gt; 2019-03-30 20:09:30 SMTP ERROR: Failed to connect to server: (0)&lt;br&gt; SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting&lt;br&gt; Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

I think the issue is the combination of the port and the security. If $mail->SMTPSecure = 'ssl', then the port number you should use is probably 465. If you use port 587, it should be combined with $mail->SMTPSecure = 'tls'.

You can use port 465 or port 587, but normally they use different encryption. And your configuration should reflect that.

Hello @Admin,
I tried the fix and changed it to tls with port 587 but here is the error.
2019-03-31 16:47:14 SERVER -&gt; 
CLIENT: 220 smtp3o.mail.yandex.net 
ESMTP (Want to use Yandex.Mail for your domain? 
Visit http://pdd.yandex.ru)
<br> 2019-03-31 16:47:14 CLIENT -&gt; 
SERVER: EHLO ravenitsolutions.com
<br> 2019-03-31 16:47:14 SERVER -&gt; 
CLIENT: 250-smtp3o.mail.yandex.net250-8BITMIME250-PIPELINING250-SIZE 
42991616250-STARTTLS250-AUTH LOGIN PLAIN XOAUTH2250-DSN250 ENHANCEDSTATUSCODES
<br> 2019-03-31 16:47:14 CLIENT -&gt; SERVER: STARTTLS
<br> 2019-03-31 16:47:14 SERVER -&gt; CLIENT: 220 Go ahead
<br> SMTP Error: Could not connect to SMTP host.
<br> 2019-03-31 16:47:14 CLIENT -&gt; SERVER: QUIT
<br> 2019-03-31 16:47:14 
<br> 2019-03-31 16:47:14 
<br> SMTP connect() failed. 
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
<br> Message could not be sent.Mailer Error: SMTP connect() failed. 
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Hello @Admin

Thanks for your support. I was able to figure out the cause which was my smtp email and password. I resulted to gmail. everything works great.

I’m glad you were able to get it fixed!

Just as a side node, please try to avoid putting extra indentation before your written text, because with Markdown formatting, that causes your text to be formatted as code, which makes it quite hard to read.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.