You are here: Home » Programming & Computer » PHP » Send Email locally via Google Server

Send Email locally via Google Server


This post will show you how to rendered gmail’s mail server to send email(s) locally.

Send Email via Gmail Server

Required Plugins:-
i) jQuery: or and saved as jquery.js – this plugin is needed for loading image to appear while page is in the middle of processing.

ii) phpmailer: – unzipped the file and saved into your local hard disk. – this plugin is needed to sent email.

How it works (Steps by steps):-

Step1: Click on “TEST SENT VIA GMAIL SERVER” button in testcenmail.php

Step2: After Click on “TEST SENT VIA GMAIL SERVER” button

Step3: Acknowledgement received showing email successfully sent out.

Step4: Recipient received the email

How to Code ?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Sent Email by Rendering Gmail Mail Server</title>
<link rel="stylesheet" type="text/css" href="cmail.css"/>
<script type="text/javascript" src="jq/src/jquery.js"></script>
<script type="text/javascript">



<div id="loading">
  <img id="loading-image" src="loading1.gif" alt="Loading..." />

<form id='form1' name='form1' action='cenmail.php' method='POST'>
		<input name='submit' id='submit' type='submit' value='TEST SENT VIA GMAIL SERVER'/>


Figure1: testcenmail.php – Interface

/* ------------------------------
File:	cmail.css
Author: LJ LEE
------------------------------ */

/* ---------------
Loading img styles
--------------- */

#loading {
  width: 100%;
  height: 100%;
  top: 0px;
  left: 0px;
  position: fixed;
  display: none;
  opacity: 0.7;
  background-color: #fff;
  z-index: 99;
  text-align: center;

#loading-image {
  position: absolute;
  top: 300px;
  left: 550px;
  z-index: 100;

Figure2: cmail.css – stylesheet

 * cenmail.php

//includes phpmailer

$mail = new PHPMailer(); //instantiate PHPmailer class

// Your email address
$emails[] = "";		//you may includes as many emails address as you like

$mail->SMTPAuth   = true;
$mail->SMTPSecure = "ssl";                 	// sets the prefix to the server
$mail->Host       = "";      	// sets GMAIL as the SMTP server
$mail->Port       = 465;                   	// set the SMTP port
$mail->Username = "";  	// your gmail account
$mail->Password = "your-gmail-password";			   	// your gmail password
$mail->From = "";   	//Sender address
$mail->FromName = "LJLEE"; 					//Sender's name

foreach($emails as $email){
$mail->Subject = "TEST CENMAIL";
$mail->Body = "<br/>
<b>Chinese Proverbs</b><br/>
- Failure is not falling down but refusing to get up.<br/>
- People who say it cannot be done should not interrupt those who are doing it.<br/>";

$mail->WordWrap = 0;

if(!$mail->Send()){	//if email not sending
   $msg = "There was an error sending the message \n"; //Write an error message if mail isn't sent
   $msg .= "Mailer Error: ".$mail->ErrorInfo;
}else{	//email sent successfully
	$msg = "Your email had been sent out successfully to your recipient!";

//End of Sending Email


<b><?php echo $msg ?></b>

Figure3: cenmail.php – server script to sent email



Leave a Reply

Your email address will not be published. Required fields are marked *