PHP (Core & Framework)

How to send email in PHP ?


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 :

	  $subject = $_POST["subject"];
	  $message = $name.'<br>';
	  $message .= $email.'<br/>';
	  $message .= $subject.'<br>';
	  $message .= $query.'<br/>';
	  $to_email = '';
	  $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",$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.

Comment here