Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Basic PHP Website (2018) Adding a Basic Form Utilizing Object Properties and Methods

Sean Flanagan
Sean Flanagan
33,231 Points

"Invalid email address"


I put my email address in the Email field and click Send but all I get is a white screen with the above message. Why is that?

If you post your code or a snapshot of your Workspace I'd be happy to take a look. My personal suggestion would be to look back over your code for typos or other errors ... we all make them.


This was the problem however you get a 502 Bad Gateway error when using your smtp settings. If you remove the smtp from the code it works as it did in the video.

PS You should probably change your gmail password now since you left it in your snapshot for others to see.

Sean Flanagan
Sean Flanagan
33,231 Points

Darrell Conklin

So even if I fill out all the fields on the form, I'll still get that message?

Follow the instructions in the link I provided and remove the smtp settings in your code and it should work just fine.

Remove the following lines to remove smtp settings.

$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "your email";
$mail->Password = "your password";
Sean Flanagan
Sean Flanagan
33,231 Points

Hi Darrell Conklin.

I got rid of those lines and changed the $email and $details operators. It now goes to the Thanks page.

Thanks for your help.


You are very welcome :)

1 Answer

Spenser Hale
Spenser Hale
18,768 Points

Hey Sean and Darrell,

It would be good for the community to have an answer selected as best answer so this questions is not listed in the unresolved section.