»User: »Password:   Remember Me? 
CodeCrunch Webmaster Forums / Programming and Development / PHP / php mail function, how to use it?
Posted:  25 Apr 2006 11:42
Hello there,
I would like to write a simple webmail script for my site, thus I would like to know if it is possible to do this using the embedded mail send function in PHP. Thank you!
Posted:  25 Apr 2006 23:16
Yes it is possible. Just keep in mind that the mail function opens a new socket connection every time that a mail is sent. So you wouldn't want to approach sending with this method if mailing to a very large list for example - as it would simply drain a server in no time.

Here is a small sample of a working mail function that doesn't take any user input other than the variables embedded, or have any error checking etc.. :

Code:


<?php
$message = "Sending made up Larry some email!";
mail('larry@somesitesomewhere.com', 'Email For You', $message);
?>


You'll notice that by default the mail function contains three basic parameters - who it's to, the subject and the message. You can also send headers. Setting the headers is a good idea if you don't want replies sent to the mailing address, you want to declare a different content type(HTML), or you want to send copies to other addresses.