How to Send an Email in PHP

I am explaining you, how to Send an Email in PHP. email if very important functionality in website. here I will use mail() function to send email in php.

in PHP’s mail() we can send email to many recipients using headers. we can add headers such as From, Cc, and Bcc. we can also use HTML content and CSS custom design in the body of the message in email.
I am exploring PHP mail() function’s parameters below are :

mail(to,subject,message,headers,parameters) 

to : it is required parameter. in “to” we can specifies the receiver / receivers of the email.
subject : it is required parameter.we can set email’s Subject.
message : it is required parameter. we can set email’s Message to send.
headers : it is optional parameter. it will use to set/add headers information (From, Cc and Bcc). Several headers must be separated by a CRLF (\r \n).
parameters : it is optional parameters.

<?php
$to = "[email protected]";
$subject = "This is testing mail subject";
$message = "Hello There! This is a testing email message.";
$from = "[email protected]";
$headers = "From:" . $from;

mail($to,$subject,$message,$headers)
?>

Leave a Reply

Your email address will not be published. Required fields are marked *

87 − 81 =