Bummer! You must be logged in to access this page.

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

PHP Mail() function

Greetings Im having difficulties and I need a help about PHP Mail() function. I just ready the documentation about mail() function and I follow it.

there is one thing that I didn't understand, I'm having an error it is "PHP Warning: mail(): SMTP server response: 550 5.7.1 Unable to relay for asongamagin@gmail.com in F:\CastSystem\webroot\Castillo System\note_preview.php on line 27"

the line 27 is: mail($to, $subject, $message, $headers);

I'm trying to building a Contact form. OR is there easiest way to send email from website without using "mailto".

And what is the best practices for PHP for sending an email from a website.

Thanks and God Bless

Hi Dennis

The best way to send an email is to use a third party library. I have used PHP mailer class before https://github.com/PHPMailer/PHPMailer/blob/master/class.phpmailer.php. I would suggest using google's smtp or services like postmark https://postmarkapp.com to send emails. The mailto() function is fine but it assumes the server where the website is being hosted has a mail server running hence may not always work.

1 Answer

Jacob Herper
Jacob Herper
94,150 Points

Can you please post your code here?

As far as I can see you are testing the script on a local xampp installation, correct? The PHP mail() function might not work on a local setup. Please try your script online to see if it's just the local environment that's causing the error.