PHP allows you to send e-mails directly from a script.
The PHP mail() function is used to send emails from inside a script.
Syntax
Note: For the mail functions to be available, PHP requires an installed and working email system. The program to be used is defined by the configuration settings in the php.ini file. Read more in our PHP Mail reference.
The simplest way to send an email with PHP is to send a text email.
In the example below we first declare the variables ($to, $subject, $message, $from, $headers), then we use the variables in the mail() function to send an e-mail:
With PHP, you can create a feedback-form on your website. The example below sends a text message to a specified e-mail address:
Note: This is the simplest way to send e-mail, but it is not secure. In the next chapter of this tutorial you can read more about vulnerabilities in e-mail scripts, and how to validate user input to make it more secure.
For more information about the PHP mail() function, visit our PHP Mail Reference.
Your Query was successfully sent!