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
Ryan Lockhart
Courses Plus Student 1,685 PointsStuck and Confused - Contact Form
Problem: Cannot get contact form submissions sent to my website email.
I have reviewed the Contact form videos several times in the Simple php website series. I further followed Randy's advice in his blog, went through step by step. Signed up for Postmark and followed those instructions to set up a server.
When I FTP my contact.php file to my web server I immediately get a fatal error. But when I take out the
$mail->IsSMTP();
$mail->SMTPAuth = true;
the page renders fine, but unable to send an email. Looking for help on this, on day 6 of frustration.
Here's a link to my current code with the email addresses and username/password taken out.
I hope Randy or Staff find this message, in need of help!
-Ryan
1 Answer
Randy Hoyt
Treehouse Guest TeacherOn line 3, you call the IsSMTP method on an object called $mail, like this:
$mail->IsSMTP();
I think the problem is that the $mail object doesn't exist yet! You create it on line 34, like this:
$mail = new PHPMailer();
You are getting the error at line 3 because you are calling a method (IsSMTP) that doesn't exist on the $mail variable. Try moving the code you currently have at line 3-8 down after the code you currently have at line 34, like this:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.postmarkapp.com";
$mail->Port = 25;
$mail->Username = "@$@$@@$@@@$$@@";
$mail->Password = "@$@$@$@$@$@$@@";
Does that help?
Ryan Lockhart
Courses Plus Student 1,685 PointsRyan Lockhart
Courses Plus Student 1,685 PointsRandy,
Thanks for the response! I made the changes mentioned and the page does load correctly. However, I am now getting this error "There was a problem sending the email: SMTP Connect() failed."
Will the require_once("inc/phpmailer/class.phpmailer.php"); also call on the class.smtp.php file?
Possibly because the username / password ? Am I supposed to be using the one to log into my Postmark account, correct?
-Ryan
Ryan Lockhart
Courses Plus Student 1,685 PointsRyan Lockhart
Courses Plus Student 1,685 PointsI should have read the fine print, I had to change the username and password to the API key provided by Postmark.
Getting a correct thank you message on the contact.php site, but still no email.
At least I am headed in the right direction!!