How To Send Mail From PHP – All About PHP Mail

0 Flares 0 Flares ×

Sending mail from a PHP script is not at all a difficult job, sending mail from PHP is just a matter of using PHP mail function and the rest is magic. If your server or system where you are executing the PHP email script is properly configured then mail() function will work as expected but if your server is not properly configured for email related services it will not work.

For PHP mail function to work properly your php.ini file must be properly configured to use a mail server, the mail server can be a local one or can be remote one.

PHP mail function syntax: mail($to, $subject, $body)

Parameter Description: The first parameter $to is the recipient address, second parameter $subject is for the subject of the email and the third parameter is for the body of the email. Below is a simple PHP mail sample that you can use to test the mail functionality.

 

<?php

 $to = “[email protected]”;

 $subject = “Test Email”;

 $body = “Hello! This is a Test mail to test PHP mail “;

 if (mail($to, $subject, $body)) {

   echo(“Message successfully sent!”);

  } else {

   echo(“Message sending failed”);

  }

 ?>

 

But you need to be careful while using this mail function to send email from any from as spammers may spam with lot of emails. You can use captcha in the mail form to protect it from spammers. 

Guru

+Ayodhyanath Guru holds a B.Tech degree in Electrical Engineering and has worked with various prestigious clients in the IT industry and presently working as a Software Engineer. He is a part time blogger and presently authors the Jafaloo.Com blog. Being a tech enthusiast Guru likes to surf the web and blogs about interesting technical topics like How-To guides, freewares, Tutorials, Software, Gadgets, web applications etc. Apart from blogging he likes coding in Java/J2EE and PHP.

You may also like...

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 0 Flares ×