TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 04-10-2005, 12:40 AM   #1 (permalink)
The Wanderer
 
Join Date: Apr 2005
Location: Missouri, USA
Posts: 15
Thanks: 0
William is on a distinguished road
Default My first Tutorial (PHP Mail())

Well first of all I would like to say thanks for viewing my first tutorial on your board. This tutorial was requested by " Danny Needs Help".

Quote:
Originally Posted by Danny Needs Help
Form Processing/Mailing would be a good first tutorial :).
Now here we go. If you have problems understanding the tutorial please ask and I will correct the wording and help you with your problem. Now first of all there are more then just mail() to do your online eMailing. But if you just want to send eMail to someone this is the easiest way. So here we go.

First of all I think for such a easy script I will display a small sample code of the function in use and tell you how it works.

PHP Code:
<?php

$to 
"Somone@domain.ext";
$subject "My new mail() code!";
$body "This message was made by my new mail() code!";
$from "Bill@Microsoft.com";

mail($to$subject$body"From: $from);

?>
Now first of all you are wondering how does this work? Well mail() is a function and it had 4 places for data. What address to send it to, the subject of the eMail, the body of the eMail, & the headers. Now you are probably thinking where is the place to put who it's from and where do I put my username and password for my eMail account. Well first of all... you can pick who its from using the header part of mail(). You can use anyones eMail you want just pop it in and it sends it. Then when they click reply it replys to that eMail. Your probley thinking awesome! Now you HAVE to have From: in front of the header so it knows what Bill@Microsoft.com or whatever you used is for. Or its going to think ok this isn't a header "ERROR!!!". Now everything else is pretty much easy. To format a eMail you can either use HTML or to make sure its safe since some eMail clients don't use HTML you can put: \n for breaking lines .ect you would have to learn more about normal text formatting. Now I hope that teaches you but one more thing you might want to know... How to send to more then 1 person? Well do this:

PHP Code:
<?php

$to  
'blah@blah.ext' ', ';
$to .= 'blah@blah.ext' ', ';
$to .= 'blah@blah.ext' ', ';
$to .= 'blah@blah.ext';
$subject "My new mail() code!';
$body = "This message was made by my new mail() code!";
$from = "Bill@Microsoft.com";

mail(
$to$subject$body, "From$from");

?>
Now just replace the: blah@blah.ext with a eMail. now that sends the eMail to blah@blah.ext 4 times! I hope you get that. Please let me know if you don't get this. Thanks! also... http://us3.php.net/manual/en/function.mail.php is a good reference. All of those advanced programers that think this is a stupid tutorial. It's not made for you. It's made for users that want to make a simple feedback or just a way to eMail people when they sign up the site. Oh and if you wanna feel special and at bottom be like your IP address is logged you can just add $REMOTE_ADDR somewhere in the body. That variable will print there IP address. Thanks for viewing the tutorial and hope it helps.

Last edited by William : 05-05-2005 at 09:28 AM.
Send a message via AIM to William Send a message via MSN to William
William is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP 5.1.2 Released! AlEast News and Announcements 1 01-25-2006 11:56 PM
PHP 5.0.5 Released AlEast News and Announcements 0 09-20-2005 01:31 PM
PHP Tutorial Section Up and Running CreativeLogic News and Announcements 4 06-01-2005 06:32 PM


All times are GMT. The time now is 12:28 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design