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

Tom Checkley
Tom Checkley
25,165 Points

Swift mail working fine locally but not when i put it live, I've changed the path for my hosting and still not working

the following code from the video works fine

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

    $mailer = \Swift_Mailer::newInstance($transport);

    $message = \Swift_Message::newInstance();
    $message->setSubject('Message from ' . $cleanName);
    $message->setFrom(array(
        $cleanEmail => $cleanName
    ));
    $message->setTo(array('example@hotmail.com'));
    $message->setBody($cleanMessage);

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

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

However when I put the site live I change the path to the one I think is provided by my host company this is the line in the hosting settings

Sendmail path /usr/local/bin/sendmail (SMTP is enabled, free type accounts may send up to 31 emails a month)

so it looks like this -

$transport = Swift_SendmailTransport::newInstance('/usr/local/bin/sendmail -bs');

I get slim application error as follows

Details

Type: Swift_TransportException Message: Expected response code 220 but got code "", with message "" File: /srv/disk7/1677892/www/tomcheckley.co.uk/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php Line: 383

If anyone can explain I'd be much appreciative. Thanks!

commenting here because I have the same problem