Use the PHP function mail() to send an email message from a PHP script.
The first parameter of the mail() function is the email address to send the email message to.
Assuming that you are running your PHP script on the server that is the MTA for the example.com email domain, and that there is a local user called fred, all of these are valid email addresses:
- fred
The MTA thinks you are trying to send an email to the local user fred.
- fred@example.com
This is the normal form for an email address, and the one that you are probably most familiar with.
- fred @ example.com
The MTA will automatically collapse the whitespace in the email address.
Although perfectly legal, email addresses with whitespace are seldom seen today.
- "Fred Bloggs" <fred@example.com>
The MTA will automatically extract the fred@example.com from between the angular brackets.
The entire string will be added as is to the From: line of the email message.
Note that the double quotes are important—do not leave them out.
Sending an Email to More Than One RecipientAdd additional addresses to the to parameter. Separate them by a comma and a space:
fred, joe@example.com, "Jane Doe"
<jane.doe@example.com>
If you want to cc: or bcc: an email to someone, do this by adding additional headers to your email.
Please check back next week for the conclusion of this article.