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.


PHPMailer not working correctly

Hey Randy and other programmer fellows here,

I have put all the PHP code on my server, but it seems in this code:

if (!$mail->ValidateAddress($mail)) { echo "You must specify a valid email address."; exit; }

it exits the script, although I provide a valid email address :(.

If I comment/remove the exit line, It send the message ok, but I still get a warning:

Warning: preg_match() expects parameter 2 to be string, object given in /home/techyvid/public_html/inc/phpmailer/class.phpmailer.php on line 737 You must specify a valid email address.

I am using the most recent PHPMailer version.

Please help.

Thanks in advance

2 Answers

Randy Hoyt
Randy Hoyt
Treehouse Guest Teacher

I think you are checking the wrong variable. Your $mail variable is the PHPMailer object, not the email address of the sender.

if (!$mail->ValidateAddress( ____ )) {

What's the name of your variable that has that email address?

Yes, thanks. That was the problem. Appreciate it!!!