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
Paul Neumyer
15,301 PointsI can't get PHPMailer to work
After watching Randy's video on PHPMailer I have tried everything I could think of to get it to work. Someone on here recommended trying Mandrill for your mail server, and I have tried that also without any luck. Can someone help me? Here is the code with the username and password omitted.
<?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $name = trim($_POST["name"]); $email = trim($_POST["email"]); $message = trim($_POST["message"]);
if($name == "" OR $email == "" OR $message == ""){
echo "You must specify a value for name, email address, and message.";
exit;
}
foreach ($_POST as $value){
if(stripos($value, 'Content-Type:') !== FALSE){
echo "There was a problem with the information you entered.";
exit;
}
}
if($_POST["address"] != ""){
echo "Your form submission has an error";
exit;
}
$email_body = "";
$email_body = $email_body . "Name: " . $name . "<br>";
$email_body = $email_body . "Email: " . $email . "<br>";
$email_body = $email_body . "Message: " . $message . "<br>";
require 'inc/phpmailer/class.phpmailer.php';
$mail = new PHPMailer();
if(!$mail->ValidateAddress($email)){
echo "You must specify a valid email address";
exit;
}
$mail->isSMTP(); $mail->SMTPDebug = 0; $mail->Debugoutput = 'html'; $mail->Host = "smtp.mandrillapp.com"; $mail->Port = 587; $mail->SMTPAuth = true; $mail->Username = "xxxx@xxxxxxxxx.co"; $mail->Password = "xxxxxxxxxxxxxxxxxxxx"; $mail->setFrom(xxxxxx@xxxxxxxxxxxxxx.co', 'Awaken Studio'); $mail->addAddress(xxxxxx@xxxxxxxxxxxxxx.co', 'Awaken Studio'); $mail->Subject = 'PHPMailer SMTP test'; $mail->AltBody = $email_body; if (!$mail->send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?>