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 Installing SwiftMailer

Amber Hoddinott
Amber Hoddinott
6,494 Points

Can some please explain to me how to fill in the setTO() method?

I have built a site on my own apple mac computer and i am using mamp as the server at the moment, i have used all the php in this course... everything seems to be working i dont think there is anything wrong with my code. (when i send the email it redirects back to my home page, which makes me think that the email is sending it just not sending properly)

I am sure however that i am either not writing the correct thing in my setTo() method or/and i havent got something installed on my computer that makes it possible for the email to send. (i have read in another question on here i need "sendmailer") however after looking at the site and downloading it, i have to say i have no idea what to do next? please help me if that is the case.

this is my code......

$transport = Swift_SendmailTransport::newInstance('/usr/sbin/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('ahdesigns@outlook.com' => 'Ambermaria')); <--------this is where i need help i think???? $message -> setBody($cleanMsg);

thank you in advance ... any help very much appreciated!!!! :D

1 Answer

I would go with PHP Mailer (found on GitHub). That's a very simple to use PHP mailer with very little configuration needed and it works with LocalHost environments, as well. There's a lot of support found on the internet for it, as well. I hope this helps!