Wednesday, January 23, 2013
How to Send Text HTML Email Messages in PHP
1. Create a page in your HTML editor and save it with a .php suffix. This tells the server that the page uses PHP and is required for your script to function.
2. Create opening and closing PHP tags within your page to tell the server that the contents of the tags should be treated as PHP code.
?> // this is a closing tagNote: // Denotes a comment within php. Comments are ignored by the server and are used by programmers to explain sections of code.
3. Define the 'to' parameter. This is the email address you are sending a message to.$to = 'email@email.com';
4. Define the 'subject' parameter. This will be displayed in the subject line of your email message.$subject = 'This is the subject line';
5. Define the 'message' parameter in plain text. This is the actual text of the email message.$message = 'Dear Friend,/n/nThis is the text of the email.';Note: /n represents a line break and must be used as carriage return within the body of your email to properly format the text.
6. Define the 'message' parameter in HTML. Use this as an alternative to sending a plain-text email message.$message = '
HTML email title
This is an HTML email.
';You can format your email message using any tag supported by HTML.
7. Send your email message.@mail($to, $subject, $message);This line of code executes the mail() function.
8. Review your function. Make sure each line ends with a semicolon and all parameters are correct and in place. Your completed function should look like this:
$to = 'email@email.com';
$subject = 'This is the subject line';
$message = 'Dear Friend,/n/nThis is the text of the email.';
@mail($to, $subject, $message);
?>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment