Send message and email by import excel file PHP


Mail

In this example we will discuss Send message and mail by import excel file PHP.

Here Send message and eby import excel file in PHP we using 3 files these are:

index.php

<!DOCTYPE html>
<html>
<body>
	<form enctype="multipart/form-data" method="post" action="message-process.php" role="form">
		<div class="form-group">
		<input type="text" name="message">
		<label for="exampleInputFile">File Upload</label>
		<input type="file" name="file" id="file" size="150">
		<p class="help-block">Only Excel/CSV File Import.</p>
		</div>
		<button type="submit" class="btn btn-default" name="submit" value="submit">Upload</button>
    </form>
</body>
</html>

message-process.php

<?php
if(isset($_POST["submit"]))
{
	$message = $_POST['message'];
	$file = $_FILES['file']['tmp_name'];
	$handle = fopen($file, "r");
	$c = 0;
	while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
	{
	$number = $filesop[0];
	
	/* start
	 Your authentication key */
		$authKey = "130491ADE9VcIY7tsB582082d3";
		/* retrieve code */
		
		/* Multiple mobiles numbers separated by comma */ 
		$mobileNumber = $number;


		/*Sender ID,While using route4 sender id should be 6 characters long. */
		$senderId = "STUDEN";

		/* Your message to send, Add URL encoding here. */
$message = $message;

		/* Define route */
		$route = "4";
		/* Prepare you post parameters */
		$postData = array(
			'authkey' => $authKey,
			'mobiles' => $mobileNumber,
			'message' => $message,
			'sender' => $senderId,
			'route' => $route
		);

		/* YOUR API URL */
		$url="https://control.msg91.com/api/sendhttp.php";

		/* init the resource */
		$ch = curl_init();
		curl_setopt_array($ch, array(
			CURLOPT_URL => $url,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_POST => true,
			CURLOPT_POSTFIELDS => $postData
			/* ,CURLOPT_FOLLOWLOCATION => true */
		));


		/* Ignore SSL certificate verification */
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);


		/* get response */
		$output = curl_exec($ch);
$success="<h3 align='center'<Birthday Wishes Send Successfully!";
		/* Print error if any */
		if(curl_errno($ch))
		{
			echo 'error:' . curl_error($ch);
		}

		curl_close($ch);
		/* end */
		$c = $c + 1;
		}
		if($fname){
			
		echo "sucess";
		} 
		else
		{
		echo "Sorry! Unable to message.";
		}
}
?>

email-process.php

<?php
if(isset($_POST["submit"]))
{
			$message = $_POST['message'];
			$file = $_FILES['file']['tmp_name'];
			$handle = fopen($file, "r");
			$c = 0;
			while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
			{
			$mail_list = $filesop[0];
			
			/* mail start */
			$to = $mail_list;
            $subject = "My subject";
            $txt = $message;
            $headers = "From: info@studentstutorial.com" . "\r\n" .
            "CC: info@anything.com";
            mail($to,$subject,$txt,$headers);
			/* mail end */
			$c = $c + 1;
			}
			if($fname){
			echo "sucess";
			} 
			else
			{
			echo "Sorry! Unable to message.";
			}
}
?>