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

Object Not Found

I have gone over this code a few times, but continue to get the same message: "The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error."

My code is below~ any help would be greatly appreciated as I have exhausted my deadline to complete my <Code> Louisville project building a website using Composer while integrating a database that collects contact form data!

<?php require 'vendor/autoload.php'; date_default_timezone_set('America/New_York');

/Instantiate a Slim Application/ $app = new \Slim\Slim( array( 'view' => new \Slim\Views\Twig() //Set the View Class to Twig ));

/TWIG Option to 'View'/ $view = $app->view(); $view->parserOptions = array( 'debug' => true ); $view->parserExtensions = array( new \Slim\Views\TwigExtension(), );

/Serve HOME (About) Page/ $app->get('/', function() use($app){ $app->render('about.twig'); })->name('home');

/Serve CONTACTt Page/ $app->get('/contact', function() use($app){ $app->render('contact.twig'); })->name('contact');

/POST Route for Contact Submission (Using Request VAR)/ $app->post('/contact', function() use($app){ $name = $app->request->post('name'); $email = $app->request->post('email'); $msg = $app->request->post('msg'); //Sanitize Filters if(!empty($name) && !empty($email) && !empty($message)) { $cleanName = filter_var($name, FILTER_SANITIZE_STRING); $cleanEmail = filter_var($email, FILTER_SANITIZE_EMAIL); $cleanMsg = filter_var($msg, FILTER_SANITIZE_STRING); } else { //Message User indicating a 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 Website');
$message->setFrom(array(
    $cleanEmail => $cleanName
));

$message->setTo(array('principal@mistermoody.com' => 'Mister Moody'));
$message->setBody($cleanMsg);

$result = $mailer->send($message);  //Capyure output

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

});

$app->run();