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. Software Reviews - Software News, Reviews and more Coming Soon... Adapt Software Rock Reviews
Insane Visions
Insane Visions
Insane Visions - Navigation

Favorites

Get Firefox!

PHP

MySQL

Affiliates


Software Reviews

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

Insane Visions - Top Navigation


Insane Visions - Sending Mail with PHP Tutorial :: Premium PHP Scripts - AdaptCMS, AdaptBB 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: 4,543
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 - March 26th
- AdaptCMS 2.0 - January 31st
- AdaptCMS 2.0 - November 20th


Poll of the Month

Thoughts on AdaptCMS 2.0 Beta?

Hated it
I liked it
Dont intend on trying it
Havent tried it yet
Results



Latest Posts

- AdaptCMS 2.0.0 Beta Released
- AdaptCMS 2.0 - New Details
- OneCMS v2.6 - Released


Testimonials

OneCMS is simply THE best CMS I've ever worked with, due to its very powerful nature, its accessibility, and easy customizability. I would also like to thank Chuck for his continuing support. Recommended. - Firas Said, Founder/Editor, GameBrite.com




Powered by AdaptCMS
Insane Visions - Footer