PHP (Core & Framework)

How to send email in PHP ?

how-to-send-email-with-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 :

          $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 = 'info@techcafe4u.in';
	  $from_email="query@techcafe4u.in";
	  $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.

Comment here

− 5 = 2