MyBB Community Forums

Full Version: Mail Issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
MyBB was unable to send the email using the PHP mail() function.
I keep on getting this error so I went to google to find some help.

One of them was to make a testscript so I make a file called mailtest.php witht the content from  this URL
https://docs.mybb.com/1.8/faq/mail/#testing-php-mail

But the issue is I have no idea how to get the file to work?
I threw it in the Root folder bu I assume thats just not how it works
Update:

PHP could not send the mailDirect initialization of this file is not allowed.

Please make sure IN_MYBB is defined.

Got this error. I installed 1.8 fresh so I dont know where I would try to "define" this

(Pasted From Discord)
I'm not sure what you put in the file but it won't be calling any MyBB code, the file is only supposed to contain this:

<?php
 error_reporting(E_ALL);
   $to = 'YOUR_EMAIL_ADDRESS';
   if(mail($to, 'Testing mail', 'This is a mailing test to see if PHP mail works.'))
   {
    echo 'Mail was sent by PHP';
   }
   else
   {
    echo 'PHP could not send the mail';
    print_r(error_get_last());
   }
?>

Then you change the YOUR_EMAIL_ADDRESS bit to your email address. You would need to put it in a new file called test.php or something, not in an existing file. You must have other code in yours if it's trying to run anything else.

But anyway, it said it couldn't send it so it looks like PHP mail does not work on your host. It is likely you will need to use an SMTP service like Mailgun or Sendgrid or Sendinblue instead.
(2023-02-26, 07:50 PM)Matt Wrote: [ -> ]I'm not sure what you put in the file but it won't be calling any MyBB code, the file is only supposed to contain this:

<?php
 error_reporting(E_ALL);
   $to = 'YOUR_EMAIL_ADDRESS';
   if(mail($to, 'Testing mail', 'This is a mailing test to see if PHP mail works.'))
   {
    echo 'Mail was sent by PHP';
   }
   else
   {
    echo 'PHP could not send the mail';
    print_r(error_get_last());
   }
?>

Then you change the YOUR_EMAIL_ADDRESS  bit to your email address. You would need to put it in a new file called test.php or something, not in an existing file. You must have other code in yours if it's trying to run anything else.

But anyway, it said it couldn't send it so it looks like PHP mail does not work on your host. It is likely you will need to use an SMTP service like Mailgun or Sendgrid or Sendinblue instead.
Thats what I have done.
You can't have done because you wouldn't be getting the "Direct initialization of this file is not allowed." and "Please make sure IN_MYBB is defined." messages if you only had this code snippet. Those are from core MyBB files and this test script is just code to send an email (you can see it has no reference to mybb anywhere), so either you've put the code inside a core file by mistake or you've put other code in your test file.

But anyway, as I said if it's saying it couldn't send the mail, then it doesn't look like PHP mail works and you will need to use an SMTP service.
Well I redid it with the code you said and got a new error

"PHP could not send the mail"

I assume I assume I just need to use a SMTP

Thank you very much