Sending E-Mail(s) in PHP#

This tutorial is an introduction to sending E-mails using PHP. You will learn about the PHP Mail function to send email and how to Create a PHP Form that sends email(s) using this function.

PHP mail() function#

E-mails in PHP can be easily sent using the library function 'mail'. This function takes four arguments to send E-mails from a PHP web page and returns 'true' upon successful delivery of Email. The parameters of this function are as follows:

  • Recipient E-mail address
  • E-mail Subject
  • E-mail message (body)
  • Headers and additional parameters like the Sender E-mail address


mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]] )#

This function returns the boolean value 'True' if the mail is sent successfully, otherwise it returns 'False'.


To :

From :

Subject :

Message(body) : Welcome to Hyve's PHP Tutorial section

Above forms shows how to send email through PHP. And code for the above examples given below, use this code and try it.

Sample PHP Code#


//Check whether the submission is made

//Declarate the necessary variables

//Check for success/failure of delivery
echo "<span class='textred'>E-mail has been sent successfully from $mail_sub to $mail_to</span>";
echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>";


Cut 'n' Paste Code

<form name="frmsendmail" method="post" action="" onSubmit="return ValidationForm()">
      <table width="100%"  border="0">
         <td width="33%" align="right" class="text">To : 
          <td width="67%"><input name="txtEmailto2" type="text" class="input" id="txtEmailto22" size="30" maxlength="100">
          <td align="right" class="text">From : 
          <td><input name="txtEmailfrm2" type="text" class="input" id="txtEmailfrm22" size="30" maxlength="100">
          <td align="right" class="text">Subject : 
        <td><input name="txtSub2" type="text" class="input" id="txtSub22" size="30" maxlength="100">
          <td align="right" class="text">Mesage(body) : 
         <td><textarea name="txtMsg" cols="50" rows="10" class="input" id="textarea"></textarea>
          <td align="right"><input name="hidSubmit" type="hidden" id="hidSubmit" value="true">
              <input name="Submit" type="submit" class="input" value="Send">
          <td><input name="Submit2" type="reset" class="input" value="Reset">

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-1) was last changed on 24-May-2017 15:30 by UnknownAuthor
G’day (anonymous guest) My Prefs
  • View Page Source
  • This clear IPSec security association,
    clear ipsec sa peer X.X.X.X

All Pages

Page views: 2262

Private Tomcat




SQL Server




Web Mail

Windows Plesk

Linux Plesk




Persits ASPUpload

Wiki Help

Referring Pages:

JSPWiki v2.8.1