I am new to Swiftmailer and am trying to send mail via a HTML contact form on a localhost (XAMPP). After pressing the 'submit' button, the error reads:
Fatal error: Class 'Swift_SmtpTransport' not found in /Applications/XAMPP/xamppfiles/htdocs/testsite/sendmessage.php on line 23
Line 23, 24, and 25 is this section:
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'tls')
->setUsername('foobar@googlemail.com')
->setPassword('GENERATED PASSWORD');
I am expecting the mail to send at this point, and show me a 'Mail Sent' message, along with the echoed lines within the PHP file, however while I'm seeing a "Mail Sent"
confirmation I am also getting the error, and I do not receive an email.
I have consulted the documentation here, and my code contained in 'sendmessage.php'
appears to be correct:
<?php
error_reporting(E_ALL);
echo getcwd();
echo function_exists('proc_open') ? "Yep, that will work" : "Sorry, that won't work";
require_once(dirname(__FILE__)."/swift.php");
echo 'Mail sent <br />';
// Grab the post data
$name = filter_var($_POST['Name'], FILTER_SANITIZE_STRING);
$usermail = filter_var($_POST['Email'], FILTER_SANITIZE_EMAIL);
$content = filter_var($_POST['Message'], FILTER_SANITIZE_STRING);
// Construct the body of the email
$data = "Name: " . $name . "<br />" . "Email: " . $usermail . "<br />" . "Message: " . $content;
// Create the transport
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'tls')
->setUsername('foobar@googlemail.com')
->setPassword('GENERATED PASSWORD');
echo 'line 26 <br />';
// Create the mailer using the created transport
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('This is the subject')
->setFrom(array('foobar@googlemail.com' => 'Feedback Received From User'))
->setTo(array('barfoo@gmail.com', 'foobar@googlemail.com' => 'Lead Recipients'))
->setSubject('Here is your Feedback subject')
->setBody($data, 'text/html');
echo 'line 34 <br />';
// Send the message
$result = $mailer -> send($message);
echo $result;
echo 'line 39<br />';
?>
proc_open
returns a "Yep, that will work"
, but as above, I am not receiving the email in my inbox.
I have tried changing the port on the line in question to 25 and 486 with no success.
After a Google search I came across this question which seemingly had the same issue, but the accepted answer did not solve my problem.
Please note that I had a previous question regarding errors with a contact form, and this question follows on from that.