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

Having issues getting the PHP Mailer to be received by the customer.

I am using a class.phpmailer.php file to send email through a contact form. The mail is not being bounced on the host server's end. It is not making it to the client, however. I am curious if anyone has any experience with this. I am using DreamHost for the site hosting, by the way.

Any help with this would be most appreciated!

Ricky Catron
Ricky Catron
13,023 Points

Can you post the code you are using for creating a php mailer object and sending the email?

2 Answers

Devin Harris
Devin Harris
9,693 Points

Like Ricky Catron says, it's very hard to help if we don't have any code to work off of. There are several ways to implement the PHP Mailer object. I assume you are using the PHP Mailer from WorxWare...there is some good documentation here http://phpmailer.worxware.com/?pg=tutorial#2, and if you understand PHP code fairly well you can also find the GitHub project and pour through the source code. Also you may just want to double check your DreamHost configuration for the parameters you need to be passing to sendmail.

I finally got most of it setup. I am using Postmark for this. I currently have validated all of the DNS TXT data. However, I am getting an error when I try to submit the form:

"There was a problem sending the email: The following From address failed: planner@domain.com : Called Mail() without being connected."

It seems to be trying to pull the regular PHP mailer without using the SMTP function. Here is the relevant code, provided the class.phpmailer.php file doesn't need to be edited in any way. This is from the process.php file:

    <?php
    require_once("class.phpmailer.php");
    $mail = new PHPMailer(); // defaults to using php "mail()"
    if (!$mail->ValidateAddress($email)){
        echo "You must specify a valid email address.";
    }

$email_body = "";
$email_body = $email_body . "Name: " . $name . "<br />";
$email_body = $email_body . "Phone: " . $phone . "<br />";
$email_body = $email_body . "Email: " . $email . "<br />";
$email_body = $email_body . "Message: " . $message;

//Mail sending data
    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    $mail->Host = "smtp.postmarkapp.com";
    $mail->Port = 26;
    $mail->Username = "##############################";
    $mail->Password = "##############################";

    $mail->SetFrom("planner@domain.com", $name);    
    $address = "customer@email.com"; 
    $mail->AddAddress($address, "Message");
    $mail->Subject    = "Contact from your website contact form | " . $name;
    $mail->MsgHTML($email_body);

    if(!$mail->Send()) {
      echo "There was a problem sending the email: " . $mail->ErrorInfo;
      exit;
    } 

header ("Location: contact-thanks.html");
exit;
    ?>
Ricky Catron
Ricky Catron
13,023 Points

Can you try adding:

$mail->SMTPDebug = 1;

to the script so we can get some more verbose debug information?