Send emails with PHP
Last update on: 10-10-2008in this lesson like the title says, you will learn how to send emails with PHP, We will use the mail() function to do it. the basic command is like the next example.
Send a simple email:
//this is the basic form mail('myemail@mydomain.com','my subject','my message');
The above example shows you the structure to use with the mail() function; 1st the recipient, second the subject and then the message. You will see how to use this feature further, and add the sender email (from). or send an email in HTML format.
Send an email with the sender info:
//email of the receiver $to = 'myemail@mydomain.com' ; //email of the sender $from = 'From: youremail@yourdomain.com'; //the subject $subject = 'This is just an email test'; //the message body $message = 'Hello, this is my first message sent via php :-)'; //now time to send our message mail($to,$subject,$message,$from);
Caution: You've probably noticed that I added a (from) after the message in the mail() function.note that it is the only extra field that can be added, this function takes only 4 metrics, if you add another, you get an error message.
send an email message in HTML format:
//email of the receiver $to = 'myemail@mydomain.com' ; //the subject $subject = 'This is just an email test'; //email of the sender $from = 'From: youremail@yourdomain.com'; //here we define in which format the message will be sent... // in this case html format $from .="Content-Type: text/html; charset=us-ascii\r\n"; //enter here an HTML code $message = "<b>Hello!</b> This is me "; //send the message with mail() mail($to,$subject,$message,$from);
PHP and MySQL's lessons:
Introduction To PHPGet Started With PHP
PHP Variables
PHP Variables Of Environment
PHP Conditions
PHP Looping
PHP Cookies
PHP Working With Dates
PHP Working With Arrays
PHP Working With Files
PHP Play With Strings
PHP And Forms
Send Emails With PHP
The Include Statement
Get Started With MySQL
MySQL Update And Delete
The WHERE Clause
MySQL Functions
Guestbook Script
Websites Directory Script
Multiple Pages With PHP
Create Your Forum With Php

