How to use the PHP mail () function

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.