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

Michael Hulet
Michael Hulet
47,912 Points

PHPMailer problems

I'm following along the first part of the Enhancing a Simple PHP Application project, and I'm trying to get PHPMailer up and running. I've set up an account and server with Postmark, and I've deployed the project to Heroku. When I fill out the email form with totally valid information, I get the error "SMTP connect() failed.". Here is the relevant part of my code:

<?php
if(!isset($error_message)){
      $email_body =  "Name: ".$name."<br/>Email: ".$email."<br/>Message: ".$message;
      $mail->isSMTP();
      $mail->SMTPAuth = true;
      $mail->Host = "smtp.postmarkapp.com";
      $mail->Port = 25;
      $mail->Username = "My Postmark API Key";
      $mail->Password = "My Postmark API Key";
      $mail->setFrom($email, $name);
      $mail->addAddress("my@email.com", "Shirts 4 Mike");
      $mail->Subject="Contact Mike, ".$name;
      $mail->msgHTML($email_body);
      if($mail->send()){
        header("Location: contact.php?status=thanks");
        exit;
      }
      else{
        $error_message =  "Mailer Error: ".$mail->ErrorInfo;
      }
}
?>

NOTE: The <?php ?> tags are only there to enable the Treehouse Forum's syntax highlighting

Do you have any ideas what could be causing the problem, and/or how to fix it?

Chris Jones
Chris Jones
9,419 Points

Can I check you have enabled SMTP server on Postmark, if its disabled it uses REST API as default.

Login, go to your Server -> Settings -> Outbound.

In there should be an SMTP option, make sure thats enabled. If not, have you tried checking apache/php logs for any other errors that may be pertinent?

Michael Hulet
Michael Hulet
47,912 Points

Your first suggestion worked! I'm obviously pretty new to Postmark. Thanks for the help!

Chris Jones
Chris Jones
9,419 Points

No worries, I've never used it, I just created an account to take a look, I've run into similar configuration issues before, with experience you begin to start knowing where to look :)

1 Answer

Chris Jones
Chris Jones
9,419 Points

Login to postmark, go to your Server -> Settings -> Outbound.

In there should be an SMTP option, make sure that's enabled.