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

Help launching the site.

Hi Everyone,

I'm having trouble sending emails from a live server and localhost... for some reason, whenever I try to send an email the site takes me to a blank screen. I also would like to know why the site is adding an extra element to the URL, for example. my site is http://www.designstudiovega.com but when I click on about it is like this : www.designstudiovega.com/designstudiovega/ and my contact is like this : www.designstudiovega.com/designstudiovega/. How can I eliminate the designstudiovega after the main site address? making my about be the index.php. Thanks in advance!

code :

============================================       
on my htaccess : 

RewriteEngine On

# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]



============================================

on my index.php

<?php

require __DIR__ . '/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.txt', Logger::WARNING));
//
//$log->addWarning('Foo');

$app = new \Slim\Slim( array(
  'view' => new \Slim\Views\Twig()
));
$app->add(new \Slim\Middleware\SessionCookie());

$view = $app->view();
$view->parseOptions = 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 that there was a problem
    $app->flash('fail', 'All Fields Are Required');
    $app->redirect('/contact');
  }

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

  $message = \Swift_Message::newInstance();
  $message->setSubject('Email From Our Website');
  $message->setFrom(array(
    $cleanEmail => $cleanName
  ));
  $message->setTo(array('cesardlvg@gmail.com')); 
  $message->setBody($cleanMsg);

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

  if($result > 0) {
    //send a message that says thank you.
    $app->flash('success', 'Thanks so much!');
    $app->redirect('/');
  } else {
    //send message to the user that the message failed to send
    $app->flash('fail', 'Something went wrong, please try again.');
    //log that there was an error
    $app->redirect('/contact');
  }
});

$app->run();

============================================
on my main.twig



<!doctype html>

<html lang="en">
  {% block head %}
    <head>
      <meta charset="utf-8">
      <title> {% block title %} Ralph Waldo Emerson {% endblock title %} </title>
      <meta name="description" content="Ralph Waldo Emerson">
      <meta name="author" content="Treehouse">
      <link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>
      <link rel="stylesheet" href="css/master.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
      <script src="js/global.js"></script>
    </head>
  {% endblock head %}
<body>

 {% include 'flash.twig' %}


  <header>
    <h1>Ralph Waldo Emerson</h1>
    <nav>
      <a href=" {{ baseUrl() }} " class="selected">About</a>
      <a href=" {{ siteUrl('/contact') }} ">Contact</a>
    </nav>


  </header>

  <div class="emerson">
   {% block hero %} <img src="images/emerson.jpg" alt="Picture of Ralph Waldo Emerson"> {% endblock hero %}
  </div>

  <main>
    {% block content %}

    {% endblock content %}
  </main>

  <footer>
    {% block footer %}
      <p>A project from <strong><a href="http://teamtreehouse.com">Treehouse</a></strong></p>
      <nav>
         <a href=" {{ baseUrl() }} " class="selected">About</a>
         <a href=" {{ siteUrl('/contact') }} ">Contact</a>
      </nav>
    {% endblock footer %}
  </footer>

</body>
</html>