Store Front Contact Us Projects Blog PHP Tutorials Community Forums Support Downloads Client Area Homepage Charlie Page - Home to the blog of myself! Dynasty Wizard - Free game dynasties, period. php cms reviews - find the right cms for you. 24 Quotes - Jack Bauer, Tony Almeida - Season 6 Adapt Software Political Yard - Talk about politics!
Insane Visions
Insane Visions
Insane Visions - Navigation

Favorites

Get Firefox!

PHP

MySQL

Affiliates

Tutorials-Expert
Software Reviews

ApocalypticTomorrow

Tutorials Garden
AllConsoleGamers
TalkPHP
Hilarious Videos
Free Myspace Stuff

[ Apply for Affiliation ]



Scripts.com

MaxTutorial.com - Best photoshop, flash and php tutorials


Your Link Here
Your Link Here
Your Link Here

Acceptance Mark
Insane Visions - Top Navigation


Insane Visions - Sending Mail with PHP Tutorial :: Premium PHP Scripts - AdaptCMS, AdaptBB, OneCMS Sending Mail with PHP at Dec 26, 07 - 11:01 pm
News Div
Post to Digg Post to Facebook Post to Furl Post to Netscape Post to Newsvine Post to Reddit Post to Simpy Post to Spurl Post to StumbleUpon

Views: 3,971
Type: PHP
Experience Level: Beginner

Despite what you may think, sending mail is a widely used practice in most scripts. Some use other methods, but the simple PHP mail() function is safe, reliable, easy to use and very useful. Below we'll show you step-by-step different ways to use the mail() function. Including sending a basic e-mail with sender, receiver, subject and body, an e-mail with a few receivers and then a full blown example with headers, HTML e-mail and the works.

Simple E-Mail


<?php
to "billgates@yahoo.com";
subject "Hey! What's up?";
message wordwrap("This is an example message"70);
mail($ to, $ subject, $ message);
?>

Above we set a "to" address (the receiver), a subject and a message. Simple, isn't it? Next we move onto using some basic headers with this mail, as well as using wordwrap() to make the email look nice. :)

E-Mail Headers

<?php
to "billgates@yahoo.com";
subject "Hey! What's up?";
message wordwrap("This is an example message"70);

headers  "MIME-Version: 1.0";
headers .= "Content-type: text/html; charset=iso-8859-1";
headers .= "From: Charlie Page <webmaster@sitename.com>";
headers .= "Reply-To: webmaster@sitename.com";

mail($ to, $ subject, $ message, $ headers);
?>

The headers shown above are pretty simple. Setting a MIME version as well as setting it to to content-type HTML, used for HTML emails (that's next) and then putting the from and reply-to. You can set one, some or none of those, it's up to you. Now for the grandaddy, sending an HTML email along with a CC, BCC and multiple receivers.

Full HTML E-Mail

<?php
to "billgates@yahoo.com, stevejobs@microsoft.com, 
webmaster@insanevisions.com"
;
subject "Hey! What's up?";
message "
<html>
<head>
<title>Hey, whats up?!</title>
</head>
<body>

<b>Here is some bold text</b><br><br>

<table><tr><td>Table!</td></tr></table>

</body>
</html>"
;

headers  "MIME-Version: 1.0";
headers .= "Content-type: text/html; charset=iso-8859-1";
headers .= "To: Bill Gates <billgates@yahoo.com>,
Steve Jobs <stevejobs@microsoft.com>,
Charlie Page <webmaster@insanevisions.com>"
;
headers .= "From: Charlie Page <webmaster@sitename.com>";
headers .= "Reply-To: webmaster@sitename.com";
headers .= "Cc: heythere@example.com";
headers .= "Bcc: dummyname@example.com";

mail($ to, $ subjectwordwrap($ message70), $ headers);
?>

CC and BCC is as simple as putting it into the headers variable and with the content-type set to HTML, you can use HTML in the message. For multiple recipients, simple seperate with a comma!

Conclusion

This wraps up another tutorial, this one showing and explaining the usage of the PHP mail() function. With this function you can quickly, easily and securely send an email. From a newsletter, to order confirmation, the usage is almost endless and is an important function to know.

Download:

Rating:

Vote for Article:



 email

 website







Username:
Password:
Insane Visions - Login Register

AdaptCMS

AdaptBB

OneCMS

Latest Tutorials

- Basic PHP Security
- Bot Detection with PHP
- PHP and Forms


Latest Blogs

- AdaptCMS 2.0 - January 31st
- AdaptCMS 2.0 - November 20th
- AdaptCMS 2.0 - July 27th


Poll of the Month

Looking forward to AdaptCMS 2.0?

Ill have to see, depends on the beta
No thanks
Other
Awesome! Yeah! Cant wait
Results



Latest Posts

- AdaptBB 1.1
- Re: AdaptBB 1.1
- Tutorial: Relative Image URL's


Testimonials

I tried various other Content Management Systems before settling on OneCMS. None came close to the ease of use and the amazing customer service! This was my first time dealing with a CMS so naturally I had many, many questions. Amazingly they were all answered the same day, most of the time my problems were fixed in minutes! OneCMS has many great features and many more planned for future releases and I personally can't wait! I'm glad I went with OneCMS for my site VideoGamesHardcore.com!

- Hector Cortez, Founder/Editor-In-Chief, VideoGamesHardcore.com




Powered by AdaptCMS
Insane Visions - Footer