Email test fails but PHP *can* send email


The C5 dashboard email test for default PHP fails with:
The following error was found while trying to send the test email:
Unable to send mail: Unknown error

However doing putting mail('[email protected]', 'test', 'testing'); into the package's controller on_start() result in an email arriving immediately in my inbox after a page load so Apache php.ini is obviously fine and email through default PHP certainly works.

So what's going on?

View Replies: View Best Answer
surefyre replied on at Permalink Reply
Even more bizarrely using the C5 own mail object works perfectly:
$mail = \Core::make('mail');
        $mail->setBody("Dear concrete5 team\nYour CMS is by far the best I\'ve ever seen.");
        $mail->addParameter('mailContent', $body);
        $mail->load('default', 'packagehandle'); // add any parameters before loading the template
        $mail->from($from, $from_name);

But writing my own email class isn't going to suddenly make system generated emails like registration validation suddenly start working.
surefyre replied on at Permalink Reply
I'll submit a bug then so someone somewhere checks it.
surefyre replied on at Permalink Best Answer Reply
For anyone reading this with the same problem I believe I found the fix. Finally.

In my installation, for whatever reason - and this is both dev and live which were both setup as standard C5 installs from 8.2.1 individually - the validation email from and fromname are null and this causes the validation registration email to screw up.

I put this in my package controller to explicitly set the values in C5
        // Fix validation email address info cos C5 team forgot to put it in?
        \Config::save('', '[email protected]');
        \Config::save('', 'The One Group');

Now it works. I really hope this helps folks with the same issue. Will add it to my bug report.

Now just don't tell the client I spent about a day in total finding this fix...
crowljor replied on at Permalink Reply
I believe this is my issue but have no idea where to look for this. Can you give me more of a step by step of where I should find this and change the script?

Thanks for any of your help.
surefyre replied on at Permalink Reply
Of course, no problem. I actually ended up moving the code into the package install method as it really only needs to run once as it mods the config file via the C5 builtin functions. This is because I believe there's a bug in C5 which causes extra closing brackets to be written to the config file in question if it's run on every page load, which should be unnecessary anyway.

Anyhoo, this is how my package's install method starts, put any other install stuff you need for your package in there as usual. I raised a bug about this though in the meantime this would seem to work.

public function install()
        $pkg = parent::install();
        // Fix validation email address info cos C5 team forgot to put it in?
        \Config::save('', '[email protected]');
        \Config::save('', 'My site/co name');
        ... your code follows

The first line sets the FROM address for verification emails, the second line the FROM name e.g. [email protected] <My site/co name>

You could also mode the file by hand though this is the 'approved' method of doing it. In <yourc5root>/application/config/generated_overrides/concrete.php you could add:
'email' => [
         'validate_registration' => [
             'address' => '[email protected]',
             'name' => 'My site/co name',

Though the code is much easier to maintain imho