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

Stephen Shine
Stephen Shine
5,991 Points

Slim application error code 8

I seem to be getting a Slim application error code 8 when I submit my email. When I check in the mail on the console, the mail is there with all the right content. So not sure what the error is, or how to fix it.

Here the error: Type: ErrorException Code: 8 Message: Undefined variable: reuslt File: /home/treehouse/workspace/index.php Line: 58 Trace

0 /home/treehouse/workspace/index.php(58): Slim\Slim::handleErrors(8, 'Undefined varia...', '/home/treehouse...', 58, Array)

1 [internal function]: {closure}()

2 /home/treehouse/workspace/vendor/slim/slim/Slim/Route.php(468): call_user_func_array(Object(Closure), Array)

3 /home/treehouse/workspace/vendor/slim/slim/Slim/Slim.php(1357): Slim\Route->dispatch()

4 /home/treehouse/workspace/vendor/slim/slim/Slim/Middleware/Flash.php(85): Slim\Slim->call()

5 /home/treehouse/workspace/vendor/slim/slim/Slim/Middleware/MethodOverride.php(92): Slim\Middleware\Flash->call()

6 /home/treehouse/workspace/vendor/slim/slim/Slim/Middleware/PrettyExceptions.php(67): Slim\Middleware\MethodOverride->call()

7 /home/treehouse/workspace/vendor/slim/slim/Slim/Slim.php(1302): Slim\Middleware\PrettyExceptions->call()

8 /home/treehouse/workspace/index.php(67): Slim\Slim->run()

9 {main}

Here's my code: <?php

require DIR . '/vendor/autoload.php';

date_default_timezone_set("Europe/London");

use Monolog\Logger; use Monolog\Handler\StreamHandler;

$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("/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');
 $mail = \Swift_Mailer::newInstance($transport);

 $message = \Swift_Message::newInstance();
 $message->setSubject('Email from our website');
 $message->setFrom(array(
   $cleanEmail => $cleanName
 ));
 $message->setTo(array('treehouse@localhost'));
 $message->setBody($cleanMsg);

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

 if($reuslt > 0) {
   $app->redirect('/');
 } else {
   $app->redirect('/contact');
 }
});

$app->run(); ?>

2 Answers

You simply have a typo. Notice at the top of the error:

Undefined variable: reuslt

You've misspelled "result." (Slaps forehead) (We've all been there!)

Enjoy, Stephen!

Stephen Shine
Stephen Shine
5,991 Points

Ah... thanks a lot for that. A good lesson in reading things in detail.