-
Sending An E-mail
Introduction
One of the major uses of a server side scripting language is to provide a way of sending e-mail from the server and, in particular, to take form input and output it to an e-mail address. In this part I will show you how to send e-mail messages using PHP.
The Mail Command
Mail is extremely easy to send from PHP, unlike using scripting languages which require special setup (like CGI). There is actually just one command, mail() for sending mail. It is used as follows:
mail($to,$subject,$body,$headers);
In this example I have used variables as they have descriptive names but you could also just place text in the mail command. Firstly, $to. This variable (or section of the command) contains the e-mail address to which the mail will be sent. $subject is the section for the subject of the e-mail and $body is the actual text of the e-mail.
The section $headers is used for any additional e-mail headers you may want to add. The most common use of this is for the From field of an e-mai but you can also include other headers like cc and bcc.
Sending An E-mail
Before sending your mail, if you are using variables, you must, of course, set up the variable content beforehand. Here is some simple code for sending a message:
$to = "[email protected]";
$subject = "PHP Is Great";
$body = "PHP is one of the best scripting languages around";
$headers = "From: [email protected]\n";
mail($to,$subject,$body,$headers);
echo "Mail sent to $to";
This code will acutally do two things. Firstly it will send a message to [email protected] with the subject 'PHP Is Great' and the text:
PHP is one of the best scripting languages around
and the e-mail will be from [email protected]. It will also output the text:
Mail sent to [email protected]
to the browser.
-
good tutorial.
below line:
echo "Mail sent to $to";
should be imo:
echo "Mail sent to ".$to;
cheers mate.
-
how to use it , i'm a young webmaster
-
this is it :
mail($to,$subject,$body,$headers);
just you maybe have problem with smtp which in that case you must change
2 or 3 lines in your php.ini
-
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks