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

Mohammad Rifqi
PLUS
Mohammad Rifqi
Courses Plus Student 3,218 Points

Slim Application Error (The system cannot find the path specified)

This the error: Slim Application Error The application could not run because of the following error:

Details

Type: Swift_TransportException
Message: Process could not be started [The system cannot find the path specified. ]
File: C:\MAMP\htdocs\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php
Line: 294
Trace

#0 C:\MAMP\htdocs\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php(58): Swift_Transport_StreamBuffer->_establishProcessConnection()
#1 C:\MAMP\htdocs\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php(113): Swift_Transport_StreamBuffer->initialize(Array)
#2 C:\MAMP\htdocs\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\SendmailTransport.php(51): Swift_Transport_AbstractSmtpTransport->start()
#3 C:\MAMP\htdocs\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Mailer.php(79): Swift_Transport_SendmailTransport->start()
#4 C:\MAMP\htdocs\index.php(62): Swift_Mailer->send(Object(Swift_Message))
#5 [internal function]: {closure}()
#6 C:\MAMP\htdocs\vendor\slim\slim\Slim\Route.php(468): call_user_func_array(Object(Closure), Array)
#7 C:\MAMP\htdocs\vendor\slim\slim\Slim\Slim.php(1357): Slim\Route->dispatch()
#8 C:\MAMP\htdocs\vendor\slim\slim\Slim\Middleware\Flash.php(85): Slim\Slim->call()
#9 C:\MAMP\htdocs\vendor\slim\slim\Slim\Middleware\MethodOverride.php(92): Slim\Middleware\Flash->call()
#10 C:\MAMP\htdocs\vendor\slim\slim\Slim\Middleware\PrettyExceptions.php(67): Slim\Middleware\MethodOverride->call()
#11 C:\MAMP\htdocs\vendor\slim\slim\Slim\Slim.php(1302): Slim\Middleware\PrettyExceptions->call()
#12 C:\MAMP\htdocs\index.php(76): Slim\Slim->run()
#13 {main}

The code:

<?php

require '/vendor/autoload.php';
date_default_timezone_set ('Asia/Jakarta');

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

//call
$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()
    );

//define
$app->get('/', 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){
    //var_dump($app->request->post());
    $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{
        //message the user that there was the problem
        $app->redirect('/contact');
    }

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

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

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

    if($result > 0){
        //send a message that says thank you, because the message is succeed
        $app-> redirect('/');
    }else{
        //send a message to the user that the message fail to send
        //log that there was an error
        $app-> redirect('/contact');
    }


});
//run
$app->run();
Mohammad Rifqi
Mohammad Rifqi
Courses Plus Student 3,218 Points

i already try using

$transport= Swift_SmtpTransport::newInstance('smtp.gmail.com', 465);

not error but, it's redirect to /contact

did i do something wrong?

2 Answers

Hmm, you could try adding a backslash to the beginning on the class:

\Swift_SendmailTransport

I have the exact same problem. I tried it with the backslash didnt work... Any other suggestions?