Email headers are lines of text that go at the start of an email message. Headers hold information used by MTAs and MUAs. If you pass a list of additional headers into the mail() function, it will automatically add these headers to your email message. Each header in the list must be separated by \r\n. The Cc: and Bcc: Headers The Cc: and Bcc: headers allow you to send a copy of an email message to other people. All recipients will be able to see the list of addresses in the To: and Cc: lines of the email, but will not be able to see the list of addresses in the Bcc: line. The Cc: and Bcc: headers are optional. If you provide either of them (or both of them), they must follow the same rules about email addresses as the to parameter to mail(). The From: Header The From: header tells the MTA who is sending the email message. If you do not provide a From: header, PHP might or might not add one for you:
Setting the Subject The second parameter to mail() is a string containing the "subject" of the email. Whatever you put in this string will appear in the Subject: header of the email. Formatting an Email Message The third parameter to mail() is the email message itself. Plain-Text Emails Plain-text emails are normal 7-bit US-ASCII strings with each line terminated by \r\n. The following code will send a plain-text email, as long as PHP is configured to correctly send email and the MTA is working, too.
<?php // who is the email going to? // change this to be *your* email address ;-) $to = "stuart"; // what is the message? $message = "This is my first email message, sent By default, all emails sent via mail() are plain-text emails. If you want to send HTML emails, you need to create a simple MIME-encoded email. Basic HTML Emails The Multipurpose Internet Mail Extensions (MIME) define a standardized way of sending emails with attachments, and/or with content that isn't 7-bit US-ASCII. You can find a reference to the MIME standard in the "Further Reading" section at the end of this chapter. To send a basic HTML email, all you need to do is this:
Any images, links, stylesheets—anything at all that the web browser has to download—must be full URLs. Note that, for security and privacy reasons, most email clients will not automatically download anything that's referenced in an HTML email. If you want to add images to your email, you need to use attachments.
blog comments powered by Disqus |
|
|
|
|
|
|
|