Tag: mail

PHP Mail (Send Email)

If you have a contact us page or something that sends an email with the use of php, it will use the “mail()” function of PHP. Here is the function:

[code lang=”php”]mail(‘Send To’,’Email Title’,’Email Message’,’Headers’,’Parameters’);[/code]

Send To = Who the email is being sent to.
Email Title = Title of the email, appears in inbox.
Email Message = The body text of the message sent.
Headers = Specifies additional headers, like From, Cc, and Bcc.
Parameters = Specifies additional parameters.

Here is an example:

[code lang=”php”]

[/code]

You have to be careful with the mail function and using headers/parameters. These are often ways of hackers sending faulty information to the script which can allow for header infections, etc. Always be sure to clean your variables you are sending to the function.

Here is a good way to check an email with preg_match:

[code lang=”php”]
function check_email($str){
if(preg_match(“/^[a-z0-9&\’\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is”, $str)) {
$email = trim($str);
return $email;
}
}
[/code]

Enjoy!

Filed under: PHP, Web ProgrammingTagged with: ,