We can use php builtin function mail() to send email. This is very simple and easy to use function. The following code shows an example of sending email from contact us form on a web site :
$name=$_POST["name"]; $email=$_POST["email"]; $subject = $_POST["subject"]; $query=$_POST["query"]; $message = $name.'<br>'; $message .= $email.'<br/>'; $message .= $subject.'<br>'; $message .= $query.'<br/>'; $to_email = 'firstname.lastname@example.org'; $from_email="email@example.com"; $dt=date("Y-m-d"); $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $headers .= 'From: '.$from_email; mail($to_email,"Enquiry from techcafe4u.in",$message,$headers);
As above code , you can see usage of php mail() function but it does not provide many popular features such as encryption & smtp authentication so for that we can use PHPMailer. The PHPMailer is a full-featured email sending class, I will create a separate post for usage of phpmailer.