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

PHP

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:

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

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