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

still getting Slim error after fix

I made the fix as showed in the video however I am still getting a slim error. Code: $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 {
    //message the user was a problem
    $app->redirect('/contact');
}

$transport = Swift_SendmailTransport::newInstance('/usr/sbin/exim -bs');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message->setSubject('Email from our Website');
$message->setFrom(array($cleanEmail -> $cleanName));
$message->SetTo(array('ase351@yahoo.com'));
$message->SetBody($cleanMsg);

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

if($result > 0) {
    //semd a message
    $app->redirect('/');
} else {
    //send a fail message
    //log error
    $app->redirect('/contact');
}

});

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

Details

Type: ErrorException Code: 8 Message: Trying to get property of non-object File: C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\index.php Line: 47 Trace

0 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\index.php(47): Slim\Slim::handleErrors(8, 'Trying to get p...', 'C:\Users\andrew...', 47, Array)

1 [internal function]: {closure}()

2 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\slim\slim\Slim\Route.php(468): call_user_func_array(Object(Closure), Array)

3 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\slim\slim\Slim\Slim.php(1357): Slim\Route->dispatch()

4 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\slim\slim\Slim\Middleware\Flash.php(85): Slim\Slim->call()

5 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\slim\slim\Slim\Middleware\MethodOverride.php(92): Slim\Middleware\Flash->call()

6 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\slim\slim\Slim\Middleware\PrettyExceptions.php(67): Slim\Middleware\MethodOverride->call()

7 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\slim\slim\Slim\Slim.php(1302): Slim\Middleware\PrettyExceptions->call()

8 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\index.php(63): Slim\Slim->run()

9 {main}

Where or how do I fix this?

Ok I changed $cleanEmail -> $cleanName to $cleanEmail => $cleanName as i saw the syntax error on the video. However I am now getting a new error Error: he 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:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php Line: 294 Trace

0 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php(58): Swift_Transport_StreamBuffer->_establishProcessConnection()

1 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php(113): Swift_Transport_StreamBuffer->initialize(Array)

2 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\SendmailTransport.php(51): Swift_Transport_AbstractSmtpTransport->start()

3 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Mailer.php(79): Swift_Transport_SendmailTransport->start()

4 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\index.php(51): Swift_Mailer->send(Object(Swift_Message))

5 [internal function]: {closure}()

6 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\slim\slim\Slim\Route.php(468): call_user_func_array(Object(Closure), Array)

7 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\slim\slim\Slim\Slim.php(1357): Slim\Route->dispatch()

8 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\slim\slim\Slim\Middleware\Flash.php(85): Slim\Slim->call()

9 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\slim\slim\Slim\Middleware\MethodOverride.php(92): Slim\Middleware\Flash->call()

10 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\slim\slim\Slim\Middleware\PrettyExceptions.php(67): Slim\Middleware\MethodOverride->call()

11 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\vendor\slim\slim\Slim\Slim.php(1302): Slim\Middleware\PrettyExceptions->call()

12 C:\Users\andrew\Desktop\phpWebsite\firstPHPSite\index.php(63): Slim\Slim->run()

13 {main}

So now I am not sure. I am not getting a line number that is wrong