Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Jake Ford
9,230 PointsUsing PHPMailer in Windows XAMPP with SMTP to send email
I just wanted to point out that this video doesn't give any hints on what to do if you are NOT using workspaces. It took me forever to figure out how to use SMTP to send mail, but this is my code:
require( 'phpmailer/PHPMailerAutoload.php' );
$mail = new PHPMailer;
if(!$mail->validateAddress($email)){
echo 'Invalid Email Address';
exit;
}
//Creating the email body to be sent
$email_body = "";
$email_body .= "Name: " . $name . "\n";
$email_body .= "Email: " . $email . "\n";
$email_body .= "State: " . $state . "\n";
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "mail.mydomain.net";
$mail->Port = 25;
$mail->Username = "me@mydomain";
$mail->Password = "password";
//Sending the actual email
$mail->setFrom($email, $name);
$mail->addAddress('me@mydomain.com', 'Me'); // Add a recipient
$mail->isHTML(false); // Set email format to HTML
$mail->Subject = 'Calculation form results from ' . $email;
$mail->Body = $email_body;
if(!$mail->send()) {
echo 'Message could not be sent. ';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
I had to include the following files in my project:
- PHPMailerAutoload.php
- class.smtp.php
- class.phpmailer.php
In the video she tells you to use require(class.phpmailer.php), but I had to use:
require(PHPMailerAutoload.php) to get it to work.
You can also use this tutorial from treehouse that was in the notes after the video, but would still have to change your require() function to require(PHPMailerAutoload.php):
http://blog.teamtreehouse.com/sending-email-with-phpmailer-and-smtp
I'm still a little confused on why she is not doing it the way the example shows on github:
require(PHPMailerAutoload.php)

Jake Ford
9,230 PointsYep,
She does kind of explain in the next video that the current settings won't work on a live server or anywhere but workspaces for that matter, but I was trying to get this mail to send before moving onto the next video! They need to update the tutorial she mentions in the notes, too. I just posted this in case anyone else has the same problems that I did in the future.
1 Answer

jlampstack
23,918 PointsAwesome!! Thanks for sharing. But also be aware as Alena mentioned, you must be careful using this since your server can get flagged, which is not good at all if that happens.
It is best to use a separate email server.
Simon Coates
28,693 PointsSimon Coates
28,693 PointsI'd guess she kept things as simple as possible. Her focus may not have been on the email so much as using as a library and demonstrating the pattern. But i'll admit I had pretty much the same questions and irritation when i tried to use her notes to get email running on my live server.