How to use the PHP mail () function
PHP's Mail () function is used to send e-mail messages within the script.
Grammar
Mail (to,subject,message,headers,parameters)
Parameter description
Required. Specify receiver/Receive email
must be filled in. Specifies the e-mail message for the subject. Note: This parameter cannot contain any new line characters
Information must be filled in. Determine the information sent. Each row should be separated from the Low-frequency (n) segment. Line should not exceed 70 characters
The title is optional. Specify additional headings like, from, copies, and Bcc. The extra headings should be separate CRLF (R N)
parameter is optional. Specify an additional parameter mail program
Note: For mail features available, you need the PHP installation and work of the email system. The project will use the definition set in the php.ini file.
Read more about our PHP mail reference.
A simple email address for PHP
The easiest way to send an email, PHP is to send a text email.
In the following example, we first declare the variables ($ to, $ issues, $ messages, from $ $ headings),
Then we use the variables in the mail () function to send an email:
<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "hello! This is a simple e-mail message. ";
$from = "someonelse@example.com";
$headers = "From: $from";
Mail ($to, $subject, $message, $headers);
echo "Mail Sent."
?>
The message form of PHP
With PHP, you can create a feedback form on your site. The following example sends a text message to the specified e-mail address:
<?php
if (isset ($_request[' email '))
//if "Email" is filled out, send email
{
//send email
$ email = $_request[' email '];
$subject = $_request[' subject '];
$message = $_request[' message '];
Mail ("someone@example.com", "Subject: $subject",
$message, "from: $email");
echo "Thank for using our mail form";
}
else
//if "Email" is isn't filled out, display the form
{
echo "<form method= ' post ' action= ' mailform.php ' >
Email: <input name= ' email ' type= ' text '/><br/> Subject: <input name= ' Subject ' type= '
Text '/><br/> message:<br/> <textarea name= ' message ' rows= ' cols= ' '
>
< /textarea><br/>
<input type= ' Submit '/>
</form> ';
>
</body>
Note: This is the easiest way to send email, but it is not secure. In the next chapter of this tutorial, you can read more about vulnerabilities,
For more information on PHP's mail () function, please visit our PHP Mail reference.