I'm trying to use swiftmailer to send transactional emails but I always get the following error in Email.php, when I try to create swiftmailer's objects:
Warning: require_once(Swift/SmtpTransport.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Tutorials\E-commerce\inc\autoload.php on line 13
Fatal error: require_once(): Failed opening required 'Swift/SmtpTransport.php' (include_path='C:\xampp\htdocs\Tutorials\E-commerce\classes;C:\xampp\htdocs\Tutorials\E-commerce\pages;C:\xampp\htdocs\Tutorials\E-commerce\mod;C:\xampp\htdocs\Tutorials\E-commerce\inc;C:\xampp\htdocs\Tutorials\E-commerce\template;C:\xampp\php\PEAR') in C:\xampp\htdocs\Tutorials\E-commerce\inc\autoload.php on line 13
The thing is, I included composer's and swiftmailer's autoloaders (separately), so it should find the classes. I have a custom autoloader but, if I include swiftmailer's autoloader directly, even if my autoloader doesn't find the classes, the include statement should be triggered and find them right? I can get it to work if I include each class individually but that's not very practical.
This is my dirs structure:
index.php
inc
config.php
autoload.php
classes
SwiftMailer
vendor
composer.json
composer.lock
Url.php
Core.php
Email.php
Login.php
etc
pages
login.php
basket.php
etc
etc
Email.php:
<?php
// I tried including them separately (also, php has no problem in finding them):
require_once 'SwiftMailer/vendor/autoload.php';
require_once 'SwiftMailer/vendor/swiftmailer/swiftmailer/lib/swift_required.php';
class Email {
public function __construct() {
$this->objTransport = Swift_SmtpTransport::newInstance();
etc
autoload.php:
<?php
require_once('config.php');
function generic_autoloader($class_name) {
$class = explode("_", $class_name);
$path = implode('/', $class) . '.php';
require_once($path);
}
spl_autoload_register('generic_autoloader');
config.php:
It's a file where I define several constants (eg: classes directory, pages directory, root path..) and at the end I have this:
set_include_path(implode(PATH_SEPARATOR, array(
realpath(ROOT_PATH.DS.CLASSES_DIR),
realpath(ROOT_PATH.DS.PAGES_DIR),
realpath(ROOT_PATH.DS.MOD_DIR),
realpath(ROOT_PATH.DS.INC_DIR),
realpath(ROOT_PATH.DS.TEMPLATE_DIR),
get_include_path()
)));
I'm not sure if this has anything to do with the problem or not (I'm following a tutorial and I haven't quite understood this part of the code yet), so I'll leave it here:
index.php:
<?php
require_once('inc/autoload.php');
$core = new Core();
$core->run();
Core.php:
<?php
class Core {
public function run() {
ob_start();
require_once(Url::getPage()); // Url::getPage just returns the path of the current page ($_GET['page'])
ob_get_flush();
}
}
Thanks in advance!