Mr. Hasselhoff
10-16-2006, 05:22 PM
The PHP Mail function can be used for sending e-mails from your own PHP scripts. It can come in useful for things such as sending a user ther login details or mailing them your sites newsletter. The mail function works like this:
<?php
mail( To String, Subject String, Message String );
?>
The first most important parameter needed is the 'To String'. This tells the mail function where to send the message. For Example:
<?php
mail( joe_bloggs@bloggs.com, Subject String, Message String );
?>
The parameter has to be a valid e-mail address, else when the e-mail is sent it will bounce back to the server. The next parameter is the 'Subject String'. This defines the subject of the message being sent. For Example:
<?php
mail( joe_bloggs@bloggs.com, 'Test Message to Joe Bloggs', Message String );
?>
The third parameter is the 'Message String'. This defines what text is to be sent in the message, For Example:
<?php
mail( joe_bloggs@bloggs.com, 'Test Message to Joe Bloggs', 'Hello Joe, This is a test message.' );
?>
If we sent this message now, the reciever 'joe_bloggs@bloggs.com' would recieve the message 'Hello Joe, This is a test message' with the subject 'Test Message to Joe Bloggs'.
Thats basically a simple mail command, for sending a basic e-mail to an address.
Now, if we want to define who the message was sent from, we need to add some extra parameters to our mail(); function.
<?php
mail( joe_bloggs@bloggs.com, 'Test Message to Joe Bloggs', 'Hello Joe, This is a test message.', "From: Admin <admin@bloggs.com>" );
?>
The extra parameter 'From:' at the end of the function defines who the message is to appear to be sent from.
Now we have got a command that will send an email to 'joe_bloggs@bloggs.com', with the subject as 'Test Message to Joe Bloggs', the message body containing 'Hello Joe, This is a test message' and it appearing to be sent from 'admin@bloggs.com'.
Hopefully this tutorial has given you an understanding to what the mail function does. There are many more options and ways to use it, but we will be going into some of them in coming tutorials.
Source: http://www.sharestation.com/index.php?showtopic=53820
<?php
mail( To String, Subject String, Message String );
?>
The first most important parameter needed is the 'To String'. This tells the mail function where to send the message. For Example:
<?php
mail( joe_bloggs@bloggs.com, Subject String, Message String );
?>
The parameter has to be a valid e-mail address, else when the e-mail is sent it will bounce back to the server. The next parameter is the 'Subject String'. This defines the subject of the message being sent. For Example:
<?php
mail( joe_bloggs@bloggs.com, 'Test Message to Joe Bloggs', Message String );
?>
The third parameter is the 'Message String'. This defines what text is to be sent in the message, For Example:
<?php
mail( joe_bloggs@bloggs.com, 'Test Message to Joe Bloggs', 'Hello Joe, This is a test message.' );
?>
If we sent this message now, the reciever 'joe_bloggs@bloggs.com' would recieve the message 'Hello Joe, This is a test message' with the subject 'Test Message to Joe Bloggs'.
Thats basically a simple mail command, for sending a basic e-mail to an address.
Now, if we want to define who the message was sent from, we need to add some extra parameters to our mail(); function.
<?php
mail( joe_bloggs@bloggs.com, 'Test Message to Joe Bloggs', 'Hello Joe, This is a test message.', "From: Admin <admin@bloggs.com>" );
?>
The extra parameter 'From:' at the end of the function defines who the message is to appear to be sent from.
Now we have got a command that will send an email to 'joe_bloggs@bloggs.com', with the subject as 'Test Message to Joe Bloggs', the message body containing 'Hello Joe, This is a test message' and it appearing to be sent from 'admin@bloggs.com'.
Hopefully this tutorial has given you an understanding to what the mail function does. There are many more options and ways to use it, but we will be going into some of them in coming tutorials.
Source: http://www.sharestation.com/index.php?showtopic=53820