use of php mail function

php-sniplets Add comments

PHP supplies a function named mail that sends email from your script.

The format is as follows: mail(headers,address,message,subject);

These are the values you need to fill in:

address: The e-mail address that receives the message
subject: A string that goes on the subject line of the e-mail message
message: The content that comes in the e-mail message
headers: A string that sets values for e-mail headers

You may set and send an email message as follows:

$to = “yourname@sitename.com”;
$subj = “Testing”;
$mess = “Testing the mail function”;
$headers = bcc:help@sitename.com\r\n
$mailsend = mail($to,$subj,$mess,$headers);

The message is sent to the address in the $to variable.

You are able to send the message to more than one individual by using the following argument:

$to= “yourname@sitename.com,secondname@secondsite.com”;

The $headers string in this case as well sends a blind copy of the message to support@sitename.com. You will
be able to let in more than one header as follows:

$header = “cc:info@sitename.com\r\nbcc:sales@sitename.com”;

Headers are optional. Just the first 3 parameters are needed.

The $mailsend variable holds TRUE or FALSE. However, TRUE is no guarantee that the mail will get to wherever
it is going. It just implies that it started out O.K..

2 Responses to “use of php mail function”

  1. php code and scripts » Blog Archive » use of php mail function Says:

    […] banking@millarassociates.com wrote an interesting post today onHere’s a quick excerptPHP supplies a function named mail that sends email from your script. The format is as follows: mail(headers,address,message,subject); These are the values you need to fill in: address: The e-mail address that receives the message … […]

  2. Andreas K Says:

    Better you use mb_send_mail(), so you can use your own encoding. The arguments are the same as in mail().

    You predefine mail’s encoding by mb_language($type). $type can be ‘ja’ (japanese), ‘en’ (standard iso encoding) or ‘uni’ (unicode). I prefer using UTF8 for mail in future because it’s the world wide standard for string encoding.

Leave a Reply

Entries RSS Comments RSS Login