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

Email form error - shows client/server communication

I recently completed my 1.0 version of my website and now that I uploaded it to dreamhost’s server, I’m having issues submitting the email form. When I host it locally, everything goes through with no problems. However, when on the server, it displays the email log:

SERVER -> CLIENT: 220 smtp.postmarkapp.com ESMTP sc-iad-smtp2
CLIENT -> SERVER: EHLO [website]
SERVER -> CLIENT: 250-smtp.postmarkapp.com250-PIPELINING250-SIZE 20480000250-VRFY250-ETRN250-STARTTLS250-AUTH PLAIN LOGIN CRAM-MD5 DIGEST-MD5250-AUTH=PLAIN LOGIN CRAM-MD5 DIGEST-MD5250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 334 VXNlcm5hbWU6
CLIENT -> SERVER: NzI2NzExNWItNzYwNC00ZDE2LTk0MmEtNDIwM2Y5NTM2Njk5
SERVER -> CLIENT: 334 UGFzc3dvcmQ6
CLIENT -> SERVER: NzI2NzExNWItNzYwNC00ZDE2LTk0MmEtNDIwM2Y5NTM2Njk5
SERVER -> CLIENT: 235 2.7.0 Authentication successful
CLIENT -> SERVER: MAIL FROM:<email@email.com>
SERVER -> CLIENT: 250 2.1.0 Ok
CLIENT -> SERVER: RCPT TO:<email@email.com>
SERVER -> CLIENT: 250 2.1.5 Ok
CLIENT -> SERVER: DATA
SERVER -> CLIENT: 354 End data with <CR><LF>.<CR><LF>
CLIENT -> SERVER: Date: Tue, 1 Sep 2015 18:37:37 -0700
CLIENT -> SERVER: To: <email@email.com>
CLIENT -> SERVER: From: testing <email@email.com>
CLIENT -> SERVER: Subject: Contact Us Form Submission | testing
CLIENT -> SERVER: Message-ID: <ID@[website]>
CLIENT -> SERVER: X-Priority: 3
CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.9 (https://github.com/PHPMailer/PHPMailer/)
CLIENT -> SERVER: MIME-Version: 1.0
CLIENT -> SERVER: Content-Type: multipart/alternative;
CLIENT -> SERVER: boundary="b1_fd47421ea6a5d27d781e06fe16a97192"
CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
CLIENT -> SERVER: 
CLIENT -> SERVER: --b1_fd47421ea6a5d27d781e06fe16a97192
CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii
CLIENT -> SERVER: 
CLIENT -> SERVER: Name: testingEmail: testemail@testemail.comSubject: testingMessage: testing one two three
CLIENT -> SERVER: 
CLIENT -> SERVER: 
CLIENT -> SERVER: --b1_fd47421ea6a5d27d781e06fe16a97192
CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
CLIENT -> SERVER: 
CLIENT -> SERVER: Name: testing<br>Email: testemail@testemail.com <br>Subject: testing<br>Message: testing one two three<br>
CLIENT -> SERVER: 
CLIENT -> SERVER: 
CLIENT -> SERVER: 
CLIENT -> SERVER: --b1_fd47421ea6a5d27d781e06fe16a97192--
CLIENT -> SERVER: 
CLIENT -> SERVER: .
SERVER -> CLIENT: 250 2.0.0 Ok: queued as 896131404CB
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 Bye
Warning: Cannot modify header information - headers already sent by XXXX

I’m currently using the postmark app while hosted on dreamhost.

I’ve tried editing this field:

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

by adding:

else {
        header (“Location: [insert form confirmation page here]”)
}

but it just displays the text above on my screen. What confuses me is that it works on my local server just fine but only displays when I host it on DreamHost. Am I not redirecting the site correctly?

2 Answers

Hmm, that seems really strange! My first suggestion would be to double check you're not having to change credentials/hosts between local and live. Do you mean the email log is sent in the email, or the email log is dumped out to the page?

I probably wouldn't dump this out on a production (live) site: $mail->ErrorInfo, instead I would email it to yourself or log the error message to a file using something like monolog and install it using composer.