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 trialAaron HARPT
19,845 PointsSetting up Postmark with PHPMailer
I am wondering if someone can help me setup Postmark with PHPMailer. I have started a free trial with Postmark. Here is my code:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim(filter_input(INPUT_POST, "name", FILTER_SANITIZE_STRING));
$email = trim(filter_input(INPUT_POST, "email", FILTER_SANITIZE_EMAIL));
$message = trim(filter_input(INPUT_POST, "message", FILTER_SANITIZE_SPECIAL_CHARS));
if ($name == "" || $email == "" || $message == "") {
$error_message = "Please fill out all the required fields: Name, Email, and Message";
}
if (!isset($error_message) && $_POST["address"] != "") {
$error_message = "Bad form input";
}
require("../includes/phpmailer/PHPMailer-master/class.phpmailer.php");
$mail = new PHPMailer;
if (!isset($error_message) && !$mail->ValidateAddress($email)) {
$error_message = "Invalid Email Address";
}
if (!isset($error_message)) {
$email_body = "";
$email_body .= $message;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.postmarkapp.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'username'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom($email, $name);
$mail->addAddress('email', 'name');
$mail->isHTML(false);
$mail->Subject = 'Comment on Website from ' . $name;
$mail->Body = $email_body;
if ($mail->send()) {
header("location:index.php?status=thanks");
exit;
}
$error_message = 'Message could not be sent.';
$error_message .= 'Mailer Error: ' . $mail->ErrorInfo;
}
}
I am using gmail for my email client. Also, what does it mean on the sending email with SMTP page about using the "server API token as both a user name and password". What I would like, is instructions on how to set up postmark to work in my situation given my above code and that the email will be sent to a gmail email address.
Thanks, Aaron