I want to write an application that uses parts of the mailer part of the eden library.
I have required it via composer.json
:
"require": {
"eden/mail": "^1.0",
...
It seems though that the library isn't autloaded properly, as the call to the eden via eden('mail')->smtp(...)
function leads to:
PHP Fatal error: Call to undefined function Kopernikus\MassMailer\Service\eden() in ~/src/massmailer/src/Kopernikus/MassMailer/Service/EdenMailerFactory.php on line 20
The quick setup guides only handles the case for the one-file approach via:
include('eden.php');
eden('debug')->output('Hello World'); //--> Hello World
I don't want to add a huge libary file and include it manually. The autoloading seems to works fine, I just have to use the class directly instead of going with the eden()
function:
use Eden\Mail\Smtp;
YourClass
{
$smtp = new Smtp(
$host,
$user,
$pass,
$port = NULL,
$ssl = false,
$tls = false
);
}
The autoloading seems to works fine basically, as I can use the class directly instead of going with the eden()
function:
use Eden\Mail\Smtp;
YourClass
{
...
$smtp = new Smtp(
$host,
$user,
$pass,
$port,
$ssl,
$tls
);
}
Yet then I get weird errors like when trying to send a mail.
[Eden\Core\Exception]
Both Physical and Virtual method Eden\Mail\Smtp->_getPlainBody()
I want to go the composer route.
It seems I have to include a file via include-path
option or add someting to the autoload
, yet I am unsure.
How to load eden mailer component the composer way?
Not a solution to the question direclty, but I managed to circumvent the issue by switching to "nette/mail"
.
composer remove eden/mail
composer require nette/mail
The SMTP worked fine for me via:
$options = [
'host' => 'smtp.gmail.com',
'username' => 'YOUR_ACCOUNT',
'password' => 'YOUR_PASSWORD',
'secure' => 'ssl',
];
$mailer = new Nette\Mail\MessageSmtpMailer($options);
$message = new Nette\Mail\Message();
$message->setFrom('my.mail@gmail.com');
$message->setBody('fnord');
$message->setSubject('foo');
$message->addTo(sendTo@gmail.com);
$mailer->send($message);
From roughly looking at it, I do believe that any Eden component isn't meant to be used standalone.
Eden seems to consist of a factory function named eden()
, that cannot be autoloaded (because it's a function), and that is part of the core of this framework - thus it isn't delivered by the mail component you were using. Even the tests of this component rely on the fact that the core is present, but also the SMTP class you wanted to use has a dependency that isn't resolved by default: use Eden\System\File;
, as well as this: class \Eden\Mail\Smtp extends \Eden\Mail\Base
together with class \Eden\Mail\Base extends \Eden\Core\Base
.
This Eden framework is meant to be used either completely, or not at all. You cannot isolate components out of it.
If you are in need for a mailing library, I'd suggest https://packagist.org/packages/swiftmailer/swiftmailer. It's not a component of a framework, so you don't inherit these dependencies.