PHP plain text email

Robert Granlund
Robert Granlund used Ask the Experts™
I can not figure out why this plain text email will not send with PHP.  Any insight will be helpful:
$body = 'Dear Colleague,
If you have any questions or would like to have a brief chat, feel free to contact me.

I look forward to hearing from you.  In the mean time, best regards and have a great day.';
                       $e = "";
$subject = 'Website Stuff';
                        $headers = 'From: My Site <>' . "\r\n";
                        $headers .= 'Bcc:' . "\r\n";

                        if(mail($e, $subject, $body, $headers)) {
                            echo "mail Sent.";
                        } else {
                            echo "Mail NOT sent.";

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Does the final result say "Mail NOT sent" or are you assuming it's not sent because the recipient doesn't get it?


Okay, so change the Mail NOT sent line to include the last error message:

echo "Mail NOT sent: " . print_r(error_get_last(),true);

Then provide the resulting output.
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.


Mail NOT sent Array ( [type] => 32 [message] => Module 'ionCube Loader' already loaded [file] => Unknown [line] => 0 )


I looks like there is something wrong with my php.ini
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

When I put in my own email addresses, your code works fine.  The code is Not the problem.  I don't know why you are loading 'ionCube'??  As far as I know, to use 'ionCube', you first have to compile your PHP code with it.

My guess is that if you're not getting an error message related to mail, then you don't have mail properly configured in your system.

If you try just a basic mail() in the same file, does it work?
var_dump(mail("","Test Subject","Test body"));

If not, then it's very likely you need to review your php.ini for mail configuration issues and ensure your server has a proper mailer service/daemon running.


I had upgraded my version of php in my hosting cpanel.  It had corrupted the php.ini file and some of the services offered by my hosting company.  I deleted my php.ini and generated a new on and the issue went away.



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial