PHPMailer doesnt send mails in website ,works normal in localhost

Hi there ! , Im working on sending mails for my website , i wrote the code below , and it works great in openserver , i uploaded it in ftp , and went to my website , to try it . It doesnt send any mails to other mails , even smtp verbose debugging not showing , though again it works great in openserver (localhost)
here is my website

test-znaniya.ga/mail.php

<?php require_once('phpmailer/PHPMailerAutoload.php');

if (isset($_POST['btn'])) {

  $name = $_POST['text'];

  $email = $_POST['mail'];

  $mail = new PHPMailer;

  $mail->CharSet = 'utf-8';

  $mail->SMTPDebug = 2;

  $mail->isSMTP();

  $mail->Host = 'smtp.mail.ru';

  $mail->SMTPAuth = true;

  $mail->Username = '[email protected]';

  $mail->Password = 'HIDDEN BY MOD';

  $mail->SMTPSecure = 'ssl';

  $mail->Port = 465;

  $mail->setFrom('[email protected]');

  $mail->addAddress($email);

  $mail->isHTML(true);

  $mail->Subject = 'Namaka eli';

  $mail->Body = $name;

  $mail->AltBody = '';

  if (!$mail->send()) {

    echo 'Message could not be sent.';

    echo 'Mailer Error: ' . $mail->ErrorInfo;

  } else {

    echo 'ok';

  }

} ?>

PHP mail is restricted in Infinityfree

Read more
https://infinityfree.net/support/php-mail/

1 Like

Hello there,

Since your using PHP Mailer with SMTP and not PHP mail(), it should work.

Try troubleshooting your error here:

You might also want to check examples:

2 Likes

Really? There is no error message or log output whatsoever? It just says “ok” when you execute this code?

yes , in localhost it works , in other hosting it works too , but i want it to work in this hosting since this is the best hosting amongst other free hosting . Any suggestions why its not working ?

It doesnt even show the verbose (SMTPdebug) , although it works anywhere but here

Actually, I tested your script, and it really doesn’t print anything. No error message, but also no success message, which is odd.

Checking the Network tab in my browser, I see that the page actually returns with a status code 500, which means the code has crashed:

https://infinityfree.net/support/http-error-500/

So, in the way described in that article, I enabled error messages on your website and tried again. And presto! There was an error message:

Fatal error: require_once(): Failed opening required 'phpmailer/PHPMailerAutoload.php' (include_path='.:/usr/share/pear/') in /home/vol8_7/epizy.com/epiz_25725501/htdocs/mail.php on line 9

So there are no mails or SMTP output because PHPMailer can’t be loaded. And, looking at your account, there doesn’t seem to be a folder phpmailer in your account at all.

So can you please upload the phpmailer folder and try again?

1 Like

Yea , my mistake , i had forgotten to upload the folder , i was misled by other hosting .
However thank u very much!

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