Sending mail using PHP in Android App ||  How to Send Email using PHP mail() Function

Introduction To PHP mail?

PHP mail is the built in PHP function that is used to send emails from PHP scripts to Any Android or website through Function.

The mail function accepts the following parameters:

  • Email address
  • Subject
  • Message

Sending mail using PHP in Android App Or Kodular App

The PHP mail function has the following basic syntax



  • “$to_email_address” is the email address of the mail recipient
  • “$subject” is the email subject
  • “$message” is the message to be sent.
  • “[$headers]” is optional, it can be used to include information such as CC, BCC

    • CC is the acronym for carbon copy. It’s used when you want to send a copy to an interested person i.e. a complaint email sent to a company can also be sent as CC to the complaints board.
    • BCC is the acronym for blind carbon copy. It is similar to CC. The email addresses included in the BCC section will not be shown to the other recipients.

Simple Mail Transmission Protocol (SMTP)

PHP mailer uses Simple Mail Transmission Protocol (SMTP) to send mail.

On a hosted server, the SMTP settings would have already been set.

Step 1

Create A connection file in hosting server with below Code (as Connection.php)

PHP mailer uses Simple Mail Transmission Protocol (SMTP) to send mail.

On a hosted server, the SMTP settings would have already been set.

Change All The Highlighted Fields With Yours:


 	header("Content-Type: text/html;charset=UTF-8");
		DEFINE ('DB_USER','DbUser');
DEFINE ('DB_PASSWORD', 'DbPassword');
DEFINE ('DB_HOST', 'localhost'); //host name depends on server DEFINE ('DB_NAME', '
DbName'); $mysqli =mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } mysqli_query($mysqli,"SET NAMES 'utf8'"); define("APP_NAME",darwinbark]); define("APP_LOGO",https://darwinbark.com/assets/uploads/media-uploader/logo-11608678157.png); define("APP_FROM_EMAIL",darwinbark.tech@gmail.com]); } ?>

Step 2

Create A SendMail.php file in hosting server with below Code (as SendMail.php)

Change All The Highlighted Fields With Yours:




$OTP=rand ( 10000 , 99999 );

 $to = $_GET['email'];
        // subject
        $subject = '[IMPORTANT] '.APP_NAME.' Forgot Password Information';

        $message='<div style="background-color: #f9f9f9;" align="center"><br />
                      <table style="font-family: OpenSans,sans-serif; color: #666666;" border="0" width="600" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF">
                            <td colspan="2" bgcolor="#FFFFFF" align="center"><img src="https://'.$_SERVER['SERVER_NAME'].'/admin/assets/images/'.APP_LOGO.'" alt="header" width="120"/></td>
                            <td width="600" valign="top" bgcolor="#FFFFFF"><br>
                              <table style="font-family:OpenSans,sans-serif; color: #666666; font-size: 10px; padding: 15px;" border="0" width="100%" cellspacing="0" cellpadding="0" align="left">
                                    <td valign="top"><table border="0" align="left" cellpadding="0" cellspacing="0" style="font-family:OpenSans,sans-serif; color: #666666; font-size: 10px; width:100%;">
                                            <td><p style="color: #262626; font-size: 28px; margin-top:0px;"><strong>Dear '.$row['name'].'</strong></p>
                                              <p style="color:#262626; font-size:20px; line-height:32px;font-weight:500;">Thank you for using '.APP_NAME.',<br>
                                                Your OTP is: '.$OTP.'</p>
                                              <p style="color:#262626; font-size:20px; line-height:32px;font-weight:500;margin-bottom:30px;">Thanks you,<br />
                            <td style="color: #262626; padding: 20px 0; font-size: 20px; border-top:5px solid #52bfd3;" colspan="2" align="center" bgcolor="#ffffff">Copyright © '.APP_NAME.'.</td>


        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'From: '.APP_NAME.' <'.APP_FROM_EMAIL.'>' . "\r\n";
        // Mail it
        @mail($to, $subject, $message, $headers);

        $set['spin'][]=array('msg' => "Password has been sent on your mail!",'success'=>'1');

    header( 'Content-Type: application/json; charset=utf-8' );
    echo $val= str_replace('\\/', '/', json_encode($set,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));

Step 3

How to integrate or Send Through Kodular App |Android App Or Directkly through Php Or Postman

Through Postman Hit The Url SendMail.php As Shown

Through kodular App Block Send Email otp like 


change it with yours URL


On every Api Call An OTP Email will Be recieved As Shows In The below Image


Join Our Telegram Channel For More