Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > PHP
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

PHP PHP for some can be one of the hardest website programming codes, so do you need help on your PHP script, if it is php4, php5 or lower this is the place for you for any PHP help.

Google
Reply
 
LinkBack Thread Tools Display Modes
Old 04-11-2006, 5:05 PM   #1
Whatcha
Back Office Guy-
 
Whatcha's Avatar
 
Join Date: Mar 2006
Location: At my pc
Posts: 533
My Photos: (6)
iTrader: (0)

Banked:
MK Cash: $0.00

I am Worth:
MK Cash: $0.36
Donate

Recent Blog: None

Whatcha is just really niceWhatcha is just really niceWhatcha is just really niceWhatcha is just really niceWhatcha is just really nice
Default Basic Usage Of Php Mail Function

Php mail() Function
Simple to use function that can provide numerous benifits. In most circumstances running the mail() command directly will send the mail no need to configure any setting or have your own mailserver. For shared hosting chances are php is already set up configured to your email server if this is not the case chances are your host is pretty poor.
Basic Syntax
PHP Code:
bool mail string tostring subjectstring message [, string additional_headers [, string additional_parameters]] ) 
Breaking it down:
For a simple stright forward email the below will do the job.
PHP Code:
<?php mail("recieveing@email.com","My Email Subject","Hello World"); ?>
Using Varibles
PHP Code:
<?php mail($to,$subject,$message,$headers); ?>
Using the varibles gives much greater scope to the function allowing for greater re-use especially when use in conjuction with for example a contact form.
!Notice the inclusion of the $headers, not included in the first usage i will go into this more later on
Okay by know alot should be self evident about the usage, so i will just run through a few tips and tricks to give you some ideas for usage.
Set within a function:
Reuse the mail function within your own function
PHP Code:
function mail_this($to$subject,$message){
mail($to,$subject,$message);

Okay so that is not much use to be honest but lets play with it a little. Using the mail_this() we can pre set the some varibles that will be constitent throught out our script.
PHP Code:
function mail_this($message){
$to            ="site_admin@mysite.com";
$subject    ="Web Site Error Notification";
mail($to,$subject,$message);

By calling the function and including the varible ie mail_this(mysql_error()) you are cutting your code and time coding down by not having to repeat the same code over.
Going bit more advanced some times you are going to want to inform that the mail send or did not send, in terms of a contact form
PHP Code:
function mail_this($to$subject,$message){
if(
mail($to,$subject,$message)){
$status    "Mail Sent Okay";
}else{
$status    ="Mail ERROR";
}
return 
$status;

Calling the above provides you will a reply to as to the status of the email being sent or not so after some one fils your web contact form in and you process the form just a simple echo statement will provide some indication of the message being sent or not
PHP Code:
<?php echo $mail_this?>
Hopefully this will light some fires to get ideas brewing on use of the mail function and how to implement to make life easyier for yourself.
Okay the $headers
Using the above basic commands give a very generic email information. Some times you want to add or beautify the email to give it a more pro-look, using headers will do this and more
Tips: Multiple headers should be separated with a CRLF (\r\n).
email headers are plentyfull but their is just a few that you will probaly set, though for spam reasons it may be best to provide a full set of headers;
PHP Code:
$headers    .="From: [email]site_admin@mysite.com[/email]    \r\n"
$headers    .="Reply-To: [email]site_admin@mysite.com[/email]    \r\n"
$headers    .="Bcc:    [email]site_admin@mysite.com[/email]\r\n"
$headers    .="Cc:site_admin@mysite.com    \r\n" 
Tips: site_admin@mysite.com will print site_admin@mysite.com in the applicable field, adding SiteAdmin <site_admin@mysite.com> will hide the email address and display SiteAdmin to give a more pro-feel to your emails.
But i want to send HTML emails how??
Easy more headers
PHP Code:
$headers  'MIME-Version: 1.0' "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n" 
But i want to send attachments???
Well to send attachments involves some more headers and goes beyond the basic usage of this tutorial for the moment. Also i would reckon mend if wanting to send attachments, mass emails or just generally complex emails i would push people to view some of the ready made classes for php to assist you.
PEAR::Mail
Whatcha is offline  
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Advertisements
Old 04-14-2006, 11:34 AM   #2
weirfire
MK PitStop Member
 
weirfire's Avatar
 
Join Date: Mar 2006
Posts: 66
My Photos: (0)
iTrader: (0)

Banked:
MK Cash: $0.00

I am Worth:
MK Cash: $0.00
Donate

Recent Blog: None

weirfire will become famous soon enoughweirfire will become famous soon enough
Default

I personally use the free open source phpmailer function. It's by far the most superior piece of mailing code I've seen yet that uses the PHP mail function.

http://phpmailer.sourceforge.net/
__________________
web development Free diggs for your stories
bags of fashion - the latest in fashionable handbags
weirfire is offline  
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 04-14-2006, 12:05 PM   #3
Whatcha
Back Office Guy-
 
Whatcha's Avatar
 
Join Date: Mar 2006
Location: At my pc
Posts: 533
My Photos: (6)
iTrader: (0)

Banked:
MK Cash: $0.00

I am Worth:
MK Cash: $0.36
Donate

Recent Blog: None

Whatcha is just really niceWhatcha is just really niceWhatcha is just really niceWhatcha is just really niceWhatcha is just really nice
Default

Looks very very intresting class there Very good find especially for complex emails,

Cheers
Whatcha is offline  
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-11-2006, 2:46 AM   #4
weirfire
MK PitStop Member
 
weirfire's Avatar
 
Join Date: Mar 2006
Posts: 66
My Photos: (0)
iTrader: (0)

Banked:
MK Cash: $0.00

I am Worth:
MK Cash: $0.00
Donate

Recent Blog: None

weirfire will become famous soon enoughweirfire will become famous soon enough
Default

You're welcome. It's a fantastic piece of coding. Very neat and does practically everything you'd want from a mailer function. It's completely object oriented so any modifications needing made could be done with an extends class.
__________________
web development Free diggs for your stories
bags of fashion - the latest in fashionable handbags
weirfire is offline  
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Featured Websites
Free Space
Free Space
Free Space Free Space
Reply
Tags: , , , ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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


Featured Websites




All times are GMT +1. The time now is 12:04 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98