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!

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


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!!!