How To Send Smtp Mail By Gmail Account

smtp mail

how-to-send-smtp-mail-by-gmail :-

PHP developers use only PHP function mail() function. but, it does not Support All feature. But PHPMailer library provide us several ways of sending email: mail(), Sendmail, qmail & direct to SMTP servers. You can use any feature of SMTP-based e-mail, multiple recepients via to, CC, BCC, etc. In short: PHPMailer is an efficient way to send e-mail within PHP.

 

Now this tutorial We Learn How How To Send  Smtp Mail By Gmail Account

1. Allow less secure apps – On Yor Gmail Account

Login Yor Gmail Account and Click This link

https://myaccount.google.com/lesssecureapps

Now use this Code

<?php
//set_time_limit(0);
ini_set('max_execution_time',0);    
require 'main_lib/class.phpmailer.php';
require 'main_lib/class.smtp.php';
require 'main_lib/class.pop3.php';

 

$mail = new PHPMailer;
$mail->SMTPDebug = 3;   // Enable verbose debug output
$mail->isSMTP();                                      
$mail->Host = 'smtp.gmail.com';  
$mail->SMTPAuth = true;

$mail->Username ='xxxxxx@gmail.com'; // SMTP username
$mail->Password = 'xxxxxx'// SMTP password

//user othentication end

$mail->SMTPSecure = 'ssl'; // Accept SSL/TLS
$mail->Port = 465// TCP port to connect to

//From email address
$mail->SetFrom('xxxxxx@gmail.com','name');

//sender email address
$mail->addAddress('xxxxx@gmail.com');


//$mail->addCC('cc@secure.com');
//$mail->addBCC('bcc@secure.com');

$mail->Debugoutput = 'html';
$mail->isHTML(true); // Set email format to HTML

$mail->Subject = 'subject';
$mail->Body    = 'body';

//for image template
/*
$mail->Body    .= '<a href="google.com" target="blank"><img alt="poster" src="cid:1001"></a>';

$filepath= "poster/Desert.jpg";
$filecid = 1001;
$filename= 'Desert.jpg';
//Encoding
 
$encoding = 'base64';
$mail->AddEmbeddedImage($filepath, $filecid, $filename, $encoding);
*/
if(!$mail->send()) {

    return 'Message could not be sent Mailer Error: ' . $mail->ErrorInfo;
    
} else{
    
    echo"massage send";
}

?>

Recommended Posts

Leave a Reply

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

Trusted by Ethereum Code Trading