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.


PhpMailer + 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:


    $mail = new PHPMailer();

        $mail->SMTPAuth = true;
    $mail->Host = "smtp.postmarkapp.com";
    $mail->Port = 2525;
    $mail->Username = "API-Key";
    $mail->Password = "API-Key";
    $mail->SMTPDebug = 1;

    $mail->addAddress('mymail@gmail.com', 'John Doe');

    $mail->Subject = 'PHPMailer mail() test';


    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;

    header("Location: contact.php?status=thanks");

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
Andrew McCormick
17,729 Points

Did 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?

Yeah 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
Andrew McCormick
17,729 Points

yes. your host could be blocking the smtp ports. I would call them or start a support ticket to find out.