Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Building Websites with PHP Contact Form & Sending Email Sending Our Email

Amr Aly
Amr Aly
5,201 Points

Error :Process could not be started [The system cannot find the path specified. ] in slim

here is my index.php source code <?php require DIR . '/vendor/autoload.php';

//$log = new Monolog\Logger('name'); //$log->pushHandler(new Monolog\Handler\StreamHandler('app.txt', Monolog\Logger::WARNING)); //$log->addWarning('Wow');

$app = new \Slim\Slim( array( 'view' => new \Slim\Views\Twig() ) );

$view = $app->view(); $view->parserOptions = array( 'debug' => true );

$view->parserExtensions = array( new \Slim\Views\TwigExtension(), );

$app->get('/', function() use($app){ $app->Render('about.twig'); })->name('home');

$app->get('/home', function() use($app){ $app->Render('about.twig'); })->name('home');

$app->get('/contact', function() use($app){ $app->Render('contact.twig'); })->name('contact');

$app->post('/contact', function() use($app){ $name = $app->request->post('name'); $email = $app->request->post('email');; $msg = $app->request->post('msg');;

if (!empty($name) && !empty($email) && !empty($msg)) {
    $cleanName = filter_var($name, FILTER_SANITIZE_STRING);
    $cleanEmail = filter_var($email, FILTER_SANITIZE_EMAIL);
    $cleanMsg = filter_var($msg, FILTER_SANITIZE_STRING);
} else {
    $app->redirect('contact');
}

$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs', 465);
$mailer = \Swift_Mailer::newInstance($transport);

$message = \Swift_Message::newInstance();
$message->setSubject('Email From Our website');
$message->setFrom(array(
    $cleanEmail  => $cleanName
));
$message->setTo(array('amr.aly57@gmail.com'));
$message->setBody($cleanMsg);

$result = $mailer->send($message);

if($result > 0) {
    //Thank you
    $app->redirect('/');
} else {
    //error

    $app->redirect('contact');

}

});

$app->run();

And when i send message i get this error : Swift_TransportException Message: Process could not be started [The system cannot find the path specified. ] File: C:\wamp\www\treehouse\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php Line: 298