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

Michael Rockett
Michael Rockett
40,365 Points

Slim error message

Hi, I'm working locally using XAMPP. When I try to send the email I get this error message.

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

Thanks, Mike

Scott Evans
Scott Evans
4,236 Points

Are you sure the path you are providing is correct?

Could you provide some of the other code you are using to initialise the Swiftmail classes. That would help me to identify what might be causing the problem.

Thanks

Michael Rockett
Michael Rockett
40,365 Points

Yeah sure

<?php
require 'vendor/autoload.php';
date_default_timezone_set("Europe/London");

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

$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 {
        // message the user

        // change to /contact when on the web
        $app->redirect('/contact');
    }

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

    $message = \Swift_Message::newInstance();
    $message->setSubject('Email from out site');
    $message->setFrom(array(
        $cleanEmail => $cleanName
    ));

    $message->setTo(array('mikerockett@live.com'));
    $message->setBody($cleanMsg);

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

    if($result > 0) {
        // send thankyou message
        $app->redirect('/');
    } else {
        // send message to user that it failed
        $app->redirect('/contact'); // change to /contact when on the web
    }

});

$app->run();


?>
Scott Evans
Scott Evans
4,236 Points

Have a quick check and see if

StreamBuffer.php

Is located in the directory specified

C:\xampp\htdocs\phpcomposerpractice\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\
Michael Rockett
Michael Rockett
40,365 Points

Yeah I checked that and It's in there

Scott Evans
Scott Evans
4,236 Points

Does the WebServer has access to the file?

Michael Rockett
Michael Rockett
40,365 Points

I'm not sure it's being run locally but I did upload it to the internet and when I tried it online it didn't give an error but it didn't redirect either it just endlessly loaded but nothing would happen and tried it in different browsers aswell

Scott Evans
Scott Evans
4,236 Points

Really strange. I would suggest looking at any PHP Error Logs and seeing what you could find in there?

Michael Rockett
Michael Rockett
40,365 Points

Hmm how do I look at the error logs?

Scott Evans
Scott Evans
4,236 Points

That can depends on a huge amount of things. Can you explain your online environment to me. So for example, Server software / Web Server software and so on.

Or if you have a hosted solution with something like cpanel.

Michael Rockett
Michael Rockett
40,365 Points

Online it's got cpanel hosting. Off line I'm using aptana studio and XAMPP

Scott Evans
Scott Evans
4,236 Points

Well for PHP Specific errors, a file should have been created in the same directory as your failing mail script. This file should be called error_log.

Michael Rockett
Michael Rockett
40,365 Points

I've found it, does this mean anything to you?

[14-Jul-2015 08:41:12 CST6CDT] PHP Fatal error: require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/mikerock/public_html/test/hmm/vendor/composer/ClassLoader.php' (include_path='.:/usr/local/php53/pear') in /home/mikerock/public_html/test/hmm/vendor/composer/autoload_real.php on line 12 [14-Jul-2015 14:49:32 Europe/London] PHP Fatal error: Class 'Twig_Extension' not found in /home/mikerock/public_html/test/hmm/vendor/slim/views/TwigExtension.php on line 38 [14-Jul-2015 14:56:46 Europe/London] PHP Fatal error: Class 'Twig_TokenParserBroker' not found in /home/mikerock/public_html/test/hmm/vendor/twig/twig/lib/Twig/Environment.php on line 1187

Scott Evans
Scott Evans
4,236 Points

All i can really tell from that is that somewhere something is not finding the required files that it needs to operate, subsequently causing the errors. Even though the errors you posted are from intermittent time over the past day, and are in no way constant. Meaning your slim script isn't creating PHP Errors.

For me to be of much more help, i would have to be able to try and diagnose the problems.

Scott Evans
Scott Evans
4,236 Points

Its proving to be one of them issue without an Obvious answer :D

Michael Rockett
Michael Rockett
40,365 Points

yeah figured it would be one of those cas I've really gone through the index.php making sure I've followed exactly.