Navbar

My Blog List

Saturday, September 1, 2018

How to Send an Email (Gmail SMTP Server) in PHP

Structure of Gmail PHPMailer using PHP

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

if(isset($_POST['send']))
{
$to_id = $_POST['toid'];
$subject = $_POST['subject'];
$message = $_POST['message'];

$mail = new PHPMailer(true);

$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'your@gmail.com';
$mail->Password = 'YourPassword';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('vedprakash151994@gmail.com', 'Ved Prakash N');
$mail->addAddress($to_id);
$mail->Subject = $subject;
$mail->Body = $message;

if(!$mail->send())
{
$error = "Mailer Error: " .$mail->ErrorInfo;
echo "<div class=display> '.$error.' </div>";
}
else
{
echo " <div class=display> Message Sent </div>";
}

}
else
{
echo "<div class=display> Please Enter Valid Data </div> ";
}

?>

How to Install Gmail SMTP Server using Composer in PHP - PART - 1

Friday, August 17, 2018

Structure of Facebook PHP SDK in PHP

<?php
require_once ('vendor/autoload.php');

$fb = new Facebook\Facebook([
'app_id' => '************',
'app_secret' => '************************',
'default_graph_version' => 'v2.3',
]);

$pageAccessToken = '************************************';


try
{
$response = $fb->post('/me/feed', $pageAccessToken);
}
catch(Facebook\Exceptions\FacebookResponseException $e)
{
echo 'Graph returned an error: '.$e->getMessage();
exit;
}
catch(Facebook\Exceptions\FacebookSDKException $e)
{
echo 'Facebook SDK returned an Error: '.$e->getMessage();
exit;
}

$graphNode = $response->getGraphNode();
echo 'ID:'.$graphNode['id'];

?>

How to Auto Post Message on Facebook in PHP