Sending Mail Using PHP (With Code) - Mobile2Computer - Android, iOS, Windows, Mac, Mobiles, Computers, Reviews and How To Guides

Mobile2Computer - Android, iOS, Windows, Mac, Mobiles, Computers, Reviews and How To Guides

Everything about Mobiles and Computers

Sending Mail Using PHP (With Code)

Sending Mail With PHP:-

E-Mails are the important medium of communication and are preferred by Large Organizations and Institutes. If you are a PHP Developer or if you are learning PHP, then I tell you this is gonna be really helpful to you, as sending emails is important to notify the users about anything. You could reduce your work by employing this Function of PHP. Continue reading to find how you could achieve this and make PHP send the emails for you.

Sending Mail in PHP is easy.PHP already has a predefined function for handling mails. The name of the function is mail( ). We are going to use the PHP mail( ) function to send mail.

Sending mail directly using the PHP Function

Mail( ) Function:-

Mail( ) function was introduced in PHP to help users to send mail using the PHP Script. It has five parameters. The parameters to, subject, message are compulsory. The parameters headers and parameters are optional. 


Parameters Explanation:-

to         -> The Recipient E-Mail Address.
subject    -> The Subject of the Mail.
message    -> The Message.
headers    -> Extra details like From,Cc,Bcc. (Optional)
parameters -> Specifies additional parameter.(Optional)

*headers should be separated with (\r\n)

PHP Script for Sending Mails:-

Simple PHP Script for Sending Mail:-



     $subject="This is the subject";

     $msg="This is the message.";


Also Read:- GBWhatsApp Latest Version Free Download

Send Mail with PHP and HTML Code:-

  <!doctype html>
  <title>Send Mail With PHP</title>
  <form method="post" action="#">
  <label>Enter the Recipient E-mail:</label>
  <input type="text" name="email"><br>
  <label>Enter the Subject:</label>
  <input type="text" name="subject"><br>
  <label>Enter the Message:</label>
  <input type="text" name="message"><br>
  <input type="submit" name="submit">

   echo "Successfully sent mail.";

Also Read:-Resume Interrupted Download in Chrome

After typing the above code and saving the file with filename.php extension. Upload it to your server and you are done.

So this post was about "Sending Mail using PHP".If you liked this then please do share this with your friends. Having any doubt? Feel free to comment.  

No comments:

Post a Comment