×
Sending mail using PHP in Android App Or Kodular App

Sending mail using PHP in Android App Or Kodular App

The PHP mail function has the following basic syntax

<?php
mail($to_email_address,$subject,$message,[$headers],[$parameters]);
?>

HERE,

  • “$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:


<?php

    error_reporting(0);
 		 ob_start();
    session_start();
 
 	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:


<?php

include("connection.php");

if(isset($_GET['sendMailOtp']))
{

$OTP=rand ( 10000 , 99999 );
$OTP=$_GET['otp'];

 $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">
                        <tbody>
                          <tr>
                            <td colspan="2" bgcolor="#FFFFFF" align="center"><img src="https://'.$_SERVER['SERVER_NAME'].'/admin/assets/images/'.APP_LOGO.'" alt="header" width="120"/></td>
                          </tr>
                          <tr>
                            <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">
                                <tbody>
                                  <tr>
                                    <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%;">
                                        <tbody>
                                          <tr>
                                            <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 />
                                                '.APP_NAME.'.</p></td>
                                          </tr>
                                        </tbody>
                                      </table></td>
                                  </tr>
                                   
                                </tbody>
                              </table></td>
                          </tr>
                          <tr>
                            <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>
                          </tr>
                        </tbody>
                      </table>
                    </div>';

//print_r($message);exit

        $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));
    die();
}?>

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 



HitUrl=https://xyz.online/admin/api_v1/api.php?sendMailOtp&email=

change it with yours URL




OUTPUT:

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



×

photo Editor App

There worse by an of miles civil. Manner before lively wholly am mr indeed expect. Among every merry his yet has her. You mistress get dashwood children off.