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!
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

David Makowski
13,676 PointsPhpMailer + Postmark "connect() failed"
After following the instructions on randy's blog-post and the instructions from postmark i still don't get the mail send.
Here's my code:
require_once("inc/phpMailer/class.phpmailer.php");
require_once("inc/phpMailer/class.smtp.php");
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.postmarkapp.com";
$mail->Port = 2525;
$mail->Username = "API-Key";
$mail->Password = "API-Key";
$mail->SMTPDebug = 1;
$mail->setFrom($email,$name);
$mail->addAddress('mymail@gmail.com', 'John Doe');
$mail->Subject = 'PHPMailer mail() test';
$mail->msgHTML($emailBody);
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
header("Location: contact.php?status=thanks");
exit;
This is the Error i get:
SMTP ERROR: Failed to connect to server: Connection timed out (110) 2014-08-30 11:57:42 SMTP connect() failed. Mailer Error: SMTP connect() failed.
What's wrong here? The SMTP is enabled on Postmark.
2 Answers
Andrew McCormick
17,730 PointsDid you try other ports like 25 or 587? Are you making sure that your api key is correct with no spaces on at the beginning or end?

David Makowski
13,676 PointsYeah it is. Also when i used this code to send a mail from my local apache server...it worked.
Could this be a problem with the hosting site? That i need some kind of authentification or signature?? The website is hostet at hostinger.in.
Andrew McCormick
17,730 Pointsyes. your host could be blocking the smtp ports. I would call them or start a support ticket to find out.
Andrew McCormick
17,730 Pointsyou might also want to try using the Postmark API instead of SMTP: http://www.abeautifulsite.net/sending-emails-with-postmark-and-php/