How to send email in php using smtp gmail

How-to-send-email-in-php-using-smtp-gmail

How to send email in php using smtp gmail 

In this tutorial , how to send email in php using smtp gmail .

<?php
if(isset($_POST['send']))
{
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer(true); 
$name  = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$phone = strip_tags($_POST['phone']);
$query = strip_tags($_POST['query']);
$subject    = "How to send email in php using smtp gmail | Bhagauti.com"; 
$message  = "<html><body>";
$message .= "
<p>".$name.".</p>
<p>".$email.".</p>
<p>".$phone.".</p>
<p>".$query.".</p>
";
$message .= "</body></html>";
try
   {
    $mail->IsSMTP(); 
    $mail->isHTML(true);
    $mail->SMTPDebug  = 0;                     
    $mail->SMTPAuth   = true;                  
    $mail->SMTPSecure = "ssl";                 
    $mail->Host       = "smtp.gmail.com";      
    $mail->Port       = 465;             
    $mail->AddAddress("Receiver Gamil Address");
    $mail->Username   ="Gmail Username";  
    $mail->Password   ="Gmail Password";            
    $mail->SetFrom( $email,  $name);
    $mail->AddReplyTo( $email, $name);
    $mail->Subject    = $subject;
    $mail->Body    = $message;
    $mail->AltBody    = $message;
   if($mail->Send())
    {
   echo '<script>alert("Message sent!");</script>';
  }
   }
   catch(phpmailerException $ex)
   {
    $msg = "<div class='alert alert-warning'>".$ex->errorMessage()."</div>";
   }
}
?>
<!DOCTYPE html>
<html>
<head>
	<title>How to send email in php using smtp gmail | Bhagauti.com</title>
	<style type="text/css">
	 body
	 {
	 	width: 100%;
	 	padding: 0;
	 	margin: 0;
	 	background-color: #060125;
	 	text-align: center;
	 	color: white
	 }	
     .input
       {
       	width: 500px;
       	line-height: 3em;
       	margin:10px 0px;
       	border-radius: 5px;
       	border:2px solid red;
       	padding-left: 5px;
       	color: black;
       	outline: none;
       	font-size: 15px
       }
       .submit
       {
       	width: 160px;
       	line-height: 2.5em;
       	margin:10px 0px;
       	border-radius: 5px;
       	border:none;
       	padding-left: 5px;
       	color: black;
       	outline: none;
       	font-size: 15px;
       	font-weight: 900;
       	background-color: white
       }
	</style>
</head>
<body>

<h1 >How to send email in php using smtp gmail </h1>

<form action="" method="post">
<input class="input" type="text" name="name" placeholder="Name">
<br/>
<input class="input" class="input" type="email" name="email" placeholder="Email">
<br/>
<input class="input" class="input" type="telephone" name="phone" placeholder="Ph.no">
<br/>
<textarea class="input" name="query" placeholder="Query"></textarea>
<br/>
<input class="submit" type="submit" name="send" value="Send Mail">
</form>
</body>
</html>

DOWNLOAD CODE  

 

ADD COMMENT

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







Roosevelt Tresch
18/02/2018

I liked your article. Did you know that Google has introduced Gmail Go? Go not only takes up significantly less space on your phone, but uses less data than the standard Gmail app.

The primary motive of our company is to provide beyond satisfactory results .

Request a free consultation quote

WWW.BHAGAUTI.COM © COPYRIGHT 2018 | TERMS AND CONDITIONS | Privacy & Policy