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

how can i solve this problem Slim Application Error

Details

Type: Swift_TransportException Message: Expected response code 220 but got code "", with message "" File: /home/treehouse/workspace/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php Line: 383

I see that you are using workspaces. Please post a link to a snapshot of your workspace. Do that by clicking the camera icon in the upper rights, creating the snapshot, opening it, and copying the URL. Post that here and we can see what is going on.

Actually, it may not be workspaces. We need your code somehow to help you.

If you are not using workspaces, do you have a local server?

I'm getting the same error message trying to run it locally

We need code examples to work with. Either copy and paste or do a Workspaces snapshot by using the camera icon on the upper right side of workspaces.

This is the error message showing in the browser:

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

Details

Type: Swift_TransportException Message: Expected response code 220 but got code "", with message "" File: /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php Line: 383 Trace

0 /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(289): Swift_Transport_AbstractSmtpTransport->_assertResponseCode('', Array)

1 /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(117): Swift_Transport_AbstractSmtpTransport->_readGreeting()

2 /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/SendmailTransport.php(51): Swift_Transport_AbstractSmtpTransport->start()

3 /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(79): Swift_Transport_SendmailTransport->start()

4 /app/index.php(55): Swift_Mailer->send(Object(Swift_Message))

5 [internal function]: {closure}()

6 /app/vendor/slim/slim/Slim/Route.php(468): call_user_func_array(Object(Closure), Array)

7 /app/vendor/slim/slim/Slim/Slim.php(1357): Slim\Route->dispatch()

8 /app/vendor/slim/slim/Slim/Middleware/Flash.php(85): Slim\Slim->call()

9 /app/vendor/slim/slim/Slim/Middleware/MethodOverride.php(92): Slim\Middleware\Flash->call()

10 /app/vendor/slim/slim/Slim/Middleware/PrettyExceptions.php(67): Slim\Middleware\MethodOverride->call()

11 /app/vendor/slim/slim/Slim/Slim.php(1302): Slim\Middleware\PrettyExceptions->call()

12 /app/index.php(64): Slim\Slim->run()

13 {main}

This is my code:

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

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

// $log = new Logger('name');
// $log->pushHandler(new StreamHandler('app.log', Logger::WARNING));
// $log->addWarning('Oh Noes.');

$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('index.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');
    $message = $app->request->post('message');
    if (!empty($name) && !empty($email) && !empty($message)){
        $cleanName = filter_var($name, FILTER_SANITIZE_STRING);
        $cleanEmail = filter_var($email, FILTER_SANITIZE_EMAIL);
        $cleanMessage = filter_var($message, FILTER_SANITIZE_STRING);
    } else {
        $app->redirect('/contact');
    }

    $transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
    $mailer = \Swift_Mailer::newInstance($transport);
    $message = \Swift_Message::newInstance();
    $message->setSubject('Email from the website');
    $message->setFrom(array(
        $cleanEmail => $cleanName
        ));
    $message->setTo(array('craig.kuriger@icloud.com'));
    $message->setBody($cleanMessage);
    $result = $mailer->send($message);
    if($result > 0){
        $app->redirect('/');
    } else {
        $app->redirect('/contact');
    }
});


$app->run();

Edited to format code. Please review how I did this for future reference.

Hi Ted, If this helps, here is my github repo where I'm storing the project.

https://github.com/CraigKuriger/PHPsite