Forums Gallery Movies File Hosting Classifieds Jokes Free Hosting Free Blogs

Go Back   BizHat Forums > Computer Forum > PHP Programming

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-18-2008, 12:48 PM
Senior Member
BizHat Geek
 
Join Date: Jan 2008
Location: gods own country
Posts: 1,444
Smile 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 = "sanil@bizhat.com";
$subject = "PHP Is Great";
$body = "PHP is one of the best scripting languages around";
$headers = "From: designer@bizhat.com\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
sanil@bizhat.com 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
designer@bizhat.com. It will also output the text:

Mail sent to
sanil@bizhat.com

to the browser.
Reply With Quote
  #2 (permalink)  
Old 09-19-2008, 03:34 PM
Junior Member
BizHat Newbie
 
Join Date: Sep 2008
Posts: 5
Default

good tutorial.

below line:
echo "Mail sent to $to";

should be imo:
echo "Mail sent to ".$to;


cheers mate.

Reply With Quote
  #3 (permalink)  
Old 09-25-2008, 02:30 PM
Junior Member
BizHat Newbie
 
Join Date: Sep 2008
Posts: 4
Default

how to use it , i'm a young webmaster
Reply With Quote
  #4 (permalink)  
Old 12-30-2008, 05:58 AM
Junior Member
BizHat Newbie
 
Join Date: Dec 2008
Posts: 6
Default

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
Reply With Quote
  #5 (permalink)  
Old 02-02-2009, 02:09 AM
Junior Member
BizHat Newbie
 
Join Date: Feb 2009
Posts: 5
Default

thanks a lot
Reply With Quote
Reply

Bookmarks

Tags
e-mail, sending

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:46 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0