PHP mail() - send email with php

Sending email with php is very simple, few lines of code and it works.
You need to send email using php when you have a comment or contact us form, where your visitors contact you via a web page form, and you get the message to your email address, or when you have a signup / registration form and you want to send automatically a confirmation link or a welcome message to your new users.

This is how you send email using php:
<?php
$TO = "someone@something.com";
$h  = "From: me@mywebsite.com";
$message = "my message here";
mail($TO, $subject, $message, $h);
Header("Location: http://mysite.com/thankyou.html");
?>

That's it ! mail() function have 3 required parameters and one optional.
$To is the receiver email address, $subject is the subject and $message is the body of your message.
$h is optional, is the header you will send, it contains the sender email address ("FROM: me@mysite.com")

I will post next how to send a html email, and how to use SMTP Authentication which means how to choose the smtp server and use your username and password to use that server.