PHP mail() function

PHP mail() function

In this lesson we are going to show you a sample PHP script on how to send email using the PHP mail() function.

PHP mail() function arguments

  1. The email address of your recipients
  2. Email subject line (ex. Meeting, Party)
  3. The body of the message
  4. List of email header fields like “From”, “Cc”
  5. Other parameters

Note: the email address and the body of the message is the most important one, the rest are optional.

Here’s how to send a plain text email using the mail() function

<head>
<title>The PHP mail() function</title>
</head>
<?php
mail("email@domain.com", "Party", "TGIF, time to party");
?>
<body>
</body>
</html>

Save the file as simpleEmailScript.php and upload it to your webserver.

Where: email@domain.com is the address of our recipient, “Party” is the subject line the “TGIF, time to party” is our message of the body

Note: if you want to add another email address just use a comma (email@domain.com, anothermail@domain.com).

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.