In order to create a custom mail function we will need to use a certain function known as the mail() function. But, before starting to do anything there are several parameters that have to be discussed. These parameters include steps such as knowing who is the receiver of your mail (or in more known terms “who you will be sending the mail to”), who is the sender (again, also known as “who is sending you a mail”), but also the headers, message, and of course the subject.
Some of these steps may need checking every time you will be using the mail function, but in the meantime, I will show you how to create your own mail function, and afterwards we will know exactly what needs to be passed to this function (if needed) every time we use it. Email.inc will be the name of this file. This certain file will be needed with your custom mail function whenever you will be using it.
First, in this file a certain function will be needed. The function we will create (and of course, is needed) is called send_mail. Several parameters are to be included in order for the function to use them, and these are as follows:
• $to_name – As discussed before, you will need to know the receiver of your mail. This parameter will be the receiver’s name.
• $to_email – Following the parameter order listed above, this parameter is actually the e-mail address towards which the mail will be sent
• $from_name – Parameter that stands for the person who is sending the mail (Mail sender)
• $from_email – Mail sender address – the e-mail address from which the e-mail is sent.
• $subject – The subject of your email
• $message – This is obviously the parameter used for the email body – where the actual message will go.
The next step is initializing the function. After we have initialized the function there is something we need to do, but it will be a lot easier if we have register_globals turned off. What are we going to do now? Well, it is not that hard to understand – everything that is sent to our script will be taken, and we will use the $_Request superglobal upon them since this picks up everything from $_POST to $_GET responses. What does actually happen? Let’s say that you have a line like this:
$_POST[‘variablename’]
Now, using the $_REQUEST the line will be stringed into:
$varname
All of this will only make your work easier since every time you will need to use any function, it will be easier to just type $variable rather than typing $_POST[‘variable’]. Moving on to the customizing of the PHP mail function, because now it gets as simple as it can get. Now all you will have to do is to pass the variables that I have listed above to a certain function and afterwards correct headers with the mail function and you’re done. Almost in any case, there are several sets of headers that work just fine. A simple example: “nX-Mailer: PHP/" . phpversion()"
PHPPopularity: 6% [?]