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
- The email address of your recipients
- Email subject line (ex. Meeting, Party)
- The body of the message
- List of email header fields like “From”, “Cc”
- 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><?phpmail("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).