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.