PHP file on 000webhost

I have 2 domains on 000webhost. I have the exact same php file on each to do some testing. The file consists of the below:

<?PHP $to = ""; $subject = "Activate your Account"; $headers = "From:"; $body = "Email Sending Worked"; if(!mail($to, $subject, $body, $headers)) { die("We couldn't sign you up this time. Please try again"); } ?>

Simple file that sends an email when run. I have masked the email address for this purpose. I run both files through the web browser URL. One of them sends the email but the other doesn’t. They both have the same code and both don’t take any parameters so don’t know why it doesn’t work.

Has anyone seen this before or got any help?

Hi @Patrick_Cummins and welcome to the forum.

Try adding error_reporting(-1); and ini_set(‘display_errors’, ‘true’); before sending the email. Copy, paste and Google the errors and or warnings.

The PHP mail() function can fail to work for a number of reasons. Some hosts disable it altogether; others may only allow a to (or from) email address that is registered with them. If you host has a support system I would ask them. If you can’t get anywhere with that or the error messages you get after following @John_Betong’s suggestion then using a mailer such as PHPMailer in place of the mail() function.

1 Like

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