PHPMailer

How does absence of cache result in connection problems to Yandex exactly? I don’t follow your logic.

1 Like

I’ll explain.

For the record, you are making relevance of a sidenote, which is not the real issue (that we have with your hosting company).

My PHPMailer was working, in the past. I don’t know the exact date which it was working, but is somewhere in the end of 2018. Today is 18-10-2109.

Luckily I have save the working PHPMailer files.

So, today my PHPMailer does not work (I tested right now as I am writing this post).
In trying to debug my problem, I was in the search of the root cause.

So I was trying to see which entity that my website is dependent, is giving problems. Being the problem, my automatic emails not being sent (and follows InfinityFree’s advice on how to send emails: https://infinityfree.net/support/php-mail/ ).

Since my website only depends on CloudFlare, InfinityFree and the PHP language. I started with the PHP language.
I tried in every possible way, using both the latest PHPMailer package, and also my saved PHPMailer files that did work in the past.
No success.

Then I investigated in the outer layer (regarding the website visitor perspective), which is: CloudFlare. And since, CloudFlare does not cache PHP files it is not their fault.
Actually, php files can never be “cached” by CloudFlare, being the nature of php a server side language, it will always live on the web hosting provider.

So the conclusion, came to be InfinityFree’s fault.

But there is one more thing that makes this conclusion stronger: when I execute the same php script that send automatic emails from my local machine, it sends emails. No problem whatsoever.

So, I leave you with the PHP error message that I get when my site is hosted on InfinityFree.
Here it goes:

2019-10-18 14:37:22 SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. Troubleshooting · PHPMailer/PHPMailer Wiki · GitHub

UPDATE:
My sending automatic emails php script is as follows:

<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;



function send_new_book_mail_warning($book_id, $book_name, $book_author, $pdf_hash, $epub_hash) {

    // Load Composer's autoloader
    require './vendor/autoload.php';

    // load secret credentials
    require './credentials.php';


    $mail = new PHPMailer(true);

	$book_folder_link = "**SECRET**";

    try {
        // Server settings
        $mail->SMTPDebug = SMTP::DEBUG_SERVER;                  // Enable verbose debug output
        $mail->isSMTP();                                        // Set mailer to use SMTP

        $mail->Host = $smtp_hostname;							// Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                             	// Enable SMTP authentication
        $mail->Username = $smtp_username;             			// SMTP username
        $mail->Password = $smtp_password;                   	// SMTP password

        // $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;     // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;     	// Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
        
        // $mail->Port = 587;                                    	// STARTTLS TCP port to connect to
        $mail->Port = 465;										// SMTPS TCP port to connect to


        // Recipients
        $mail->setFrom('[email protected]', 'FreeWriters Website');
        //$mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
        $mail->addAddress('[email protected]');            // Name is optional
        $mail->addReplyTo('[email protected]');
        //$mail->addCC('[email protected]');
        //$mail->addBCC('[email protected]');

        // Attachments
        //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
        //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name


        // Content
        $mail->isHTML(true);                                  // Set email format to HTML

        $mail->Subject = 'New book added!';

        $message = "The library has a new book (of id: {$book_id}) that needs copyright validation.<br>The book name is {$book_name} by {$book_author}.";

        $mail->Body = $message;

        //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

        $mail->send();

    } catch (Exception $e) {

        $mail_error = $mail->ErrorInfo;

        echo "Email message warning saying that new book was added could not be sent automatically to the FreeWriters Library Maintainer.

Please notify us through the contact page (http://freewriters.org/contact/) so that we can validate your book and be available in our library.
Mailer Error: {$mail_error}

";
    }
}

I care for a reply

I understand your logic, but I don’t agree with your conclusion. Yes, your PHP code is the same, and possibly the configuration is as well. But given identical code, that doesn’t mean that the only possible culprit is the hosting it runs on.

Between end of 2018 and now, the hosting platform has evolved of course. One notable change I can think of is that the default PHP version was changed from PHP 7.0 to PHP 7.3. A new PHP version is generally not too impactful, but some software may behave differently or cease to function at all.

If this would indeed be the problem, you could of course put us at fault for keeping our software up to date. But you have to understand that running an old, unmaintained PHP version until the end of time is not a sustainable solution. We need to upgrade our software regularly to get security updates, bug fixes and other improvements, and so do you.

But just like how our hosting evolves, Yandex’s mail system evolves too. You conclude that this is our fault, but how do you know that Yandex did not cause this to happen? Maybe they blocked our IP addresses from delivering email to their servers? How are you so confident that this issue is unquestionably our fault, and not Yandex’s? “it works on my machine” is not exactly solid evidence.

All I know for certain is that SMTP from PHPmailer on InfinityFree to Yandex doesn’t work. Other SMTP software may work, other hosting may work, other email providers may work. This could be a problem with our hosting, with PHPmailer, or with Yandex. I’m not sure who is at fault. And I would like to ask you to consider alternative conclusions as well.

3 Likes

is there any correct way to make the phpmail work? i am having also this error > Mailer Error: SMTP connect() failed. Troubleshooting · PHPMailer/PHPMailer Wiki · GitHub

i try also port 465 and 587 with ssl and tls. same results.

but when i try with my local apache server it is working fine.

<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function



require './PHPMailer/PHPMailerAutoload.php';
require './PHPMailer/class.phpmailer.php';
require './PHPMailer/class.smtp.php';

$mail = new PHPMailer;
$mail->isSMTP();

/*
 * Server Configuration
 */

$mail->Host = 'smtp.yandex.com'; // Which SMTP server to use.
$mail->Port = 465; // Which port to use, 587 is the default port for TLS security.
$mail->SMTPSecure = 'ssl'; // Which security method to use. TLS is most secure.
$mail->SMTPAuth = true; // Whether you need to login. This is almost always required.
$mail->Username = "sender email"; // Your Gmail address.
$mail->Password = "my yandex password"; // Your Gmail login password or App Specific Password.

/*
 * Message Configuration
 */

$mail->setFrom('sender email', 'Semder'); // Set the sender of the message.
$mail->addAddress('contact email', 'Contact'); // Set the recipient of the message.
$mail->Subject = 'PHPMailer yandex SMTP test'; // The subject of the message.

/*
 * Message Content - Choose simple text or HTML email
 */
 
// Choose to send either a simple text email...
$mail->Body = 'This is a plain-text message body'; // Set a plain text body.

// ... or send an email with HTML.
//$mail->msgHTML(file_get_contents('contents.html'));
// Optional when using HTML: Set an alternative plain text message for email clients who prefer that.
//$mail->AltBody = 'This is a plain-text message body'; 

// Optional: attach a file
$mail->addAttachment('images/phpmailer_mini.png');

if ($mail->send()) {
    echo "Your message was sent successfully!";
} else {
    echo "Mailer Error: " . $mail->ErrorInfo;
}
?>

Since Yandex has blocked access to their SMTP server from free hosting’s IPs, I suggest you to change email provider, just like Admin said.

2 Likes

yandex smtp is working but your website must have no ssl installed. i try to use the same script in my other server here in infinityfree with no ssl intalled. :slight_smile:

or the other solution is add the below code( for site with ssl certificate):

$mail->SMTPOptions = array(
‘ssl’ => array(
‘verify_peer’ => false,
‘verify_peer_name’ => false,
‘allow_self_signed’ => true
)
);

1 Like

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