0
votes

I have downloaded Swift-mailer using composer, however when I go to test it I keep getting error messages.

This is what I have set up to set with:

<?php
require_once '/path/to/vendor/autoload.php';

// Create the Transport
 $transport = (new Swift_SmtpTransport('smtp.justbitestreats.com', >25))
->setUsername('XXXXXX')
->setPassword('XXXXXX');

// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);

// Create a message
$message = (new Swift_Message('Wonderful Subject'))
->setFrom(['[email protected]' => 'Julie'])
->setTo(['[email protected]', '[email protected]' => 'JBT'])
->setBody('Here is the message itself');

// Send the message
$result = $mailer->send($message);

I have also tried using sendmail:

<?php
require_once '/path/to/vendor/autoload.php'(include_path='D:\xampp\php\PEAR');
// Create the Transport
$transport = new Swift_SendmailTransport('/usr/sbin/sendmail -bs');

// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
// Create a message
$message = (new Swift_Message('Wonderful Subject'))
->setFrom(['[email protected]' => 'Julie'])
->setTo(['[email protected]' => 'A name'])
->setBody('Here is the message itself');

// Send the message
$result = $mailer->send($message);

I keep getting the same error messages

Here is the error message:

Warning: require_once(/path/to/vendor/autoload.php): failed to open stream: No such file or directory in D:\xampp\htdocs\dashboard\JBT-Emails\sendmail.php on line 2

Fatal error: require_once(): Failed opening required '/path/to/vendor/autoload.php' (include_path='D:\xampp\php\PEAR') in D:\xampp\htdocs\dashboard\JBT-Emails\sendmail.php on line 2

1
It seems you're trying to access a file that isn't there. - mypetlion

1 Answers

0
votes

If you have downloaded a package through composer in PHP then you should include the autoloader like this-

require_once realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . './vendor/autoload.php');

I noticed in your error that your path is-

D:\xampp\htdocs\dashboard\JBT-Emails\sendmail.php

If you directly include vendor folder in sendmail.php then it may not work so you should try to provide a full path like I have mentioned above and it will find the file.