Send mail using PHP Mail Function

This is a simple tutorial to send mail using PHP Mail Function, This code is to test whether web server is capable of sending mail or not. We are using PHP mail function.

Send mail using PHP Mail Function

Simple code for testing

[php] <?php mail(‘[email protected]’, ‘Mail Subject Line’, ‘Mail Message Body’); ?>

You can pass these values with variables, and also we can check whether the mail sent successfully or mail sending failed.

[php] <?php $to = "[email protected]";
$subject = "Mail Subject Line";
$message = "Mail Message Body";
if(mail($to, $subject, $message)){
echo "Mail Sent Successfully";
echo "Mail sending Failed";

This is Basic code to Send mail using PHP Mail Function. We can add some more functionality to this basic code, we can add additional headers like from Email Address with the Name. In headers we can also add MIME Type, content type, reply to email address, Cc and Bcc addresses.

We can add some more functionality to this by sending values through a form. I’ll add this feature in other post.

This code is useful for new or beginner PHP programmers, they can directly use this code and test their work space or server.

Vivek Vengala

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: