PHP Mail

mail() - Send mail

This function is used to send email. You can send text, html message and attachment with message using this function.

bool mail (string $filename, string $to,  string $subject,  string $message [,  string $additional_headers [,  string $additional_headers ]] ) 

Parameters:

  • to: Receiver, or receivers of the mail.
    • user@example.com
    • user@example.com, anotheruser@example.com
    • User <user@example.com>
    • User <user@example.com>, Another User <anotheruser@example.com>
  • subject: Subject of the email to be sent.
  • messagel: Message to be sent.
    Each line should be separated with a CRLF (rn). Lines should not be larger than 70 characters.
  • additional_headers (optional): String to be inserted at the end of the email header.This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (rn). If outside data are used to compose this header, the data should be sanitized so that no unwanted headers could be injected.
<?php 
  $to ="nobody@example.com";
  $subject = "the subject";
  $message = "hello";
  $headers = 'From: webmaster@example.com' . "rn" .
  'Reply-To: webmaster@example.com' . "rn" .
  'X-Mailer: PHP/' . phpversion();
  mail($to, $subject, $message, $headers);
?>