PHP GMail IMAP Connection Failure - php

I am using this repo for connecting to the gmail. But its getting error. I hope someone has experience handling this recently.
<?php
namespace program;
require_once "php-imap-client/vendor/autoload.php";
use SSilence\ImapClient\ImapClientException;
use SSilence\ImapClient\ImapConnect;
use SSilence\ImapClient\ImapClient as Imap;
$mailbox = 'imap.gmail.com';
$username = 'alice#gmail.com';
$password = "wonderland";
$encryption = Imap::ENCRYPT_SSL;
// Open connection
try{
$imap = new Imap($mailbox, $username, $password, $encryption);
// You can also check out example-connect.php for more connection options
}catch (ImapClientException $error){
echo $error->getMessage().PHP_EOL;
die(); // Oh no :( we failed
}

I've had this before too. From the link in the error message you're receiving.
Allow less secure apps: If you don't use 2-Step Verification, you
might need to allow less secure apps to access your account.
Here's a guide to do so

Related

how to receive message in xmpphp

it is clearly stated in the examples how to send message but, i am not clear with how to receive messages initiated by other client in the server any help is highly appreciated
Here is my code for sending the message
include("xmpphp/xmpp.php");
//username = user without domain, "user" and not "user#server" - home is the resource
$conn = new XMPPHP_XMPP('localhost', 5222, 'robel27', 'yoyene122127', 'kiyos');
// Enables TLS - enabled by default, call before connect()!
$conn->useEncryption(false);
$conn->connect();
// shows the user's status message
$conn->presence();
$conn->processUntil(array('session_start', 'roster_received'));
$conn->processTime(2);
$conn->message('kiyos12#kiyos', $_POST['msg1']);
$conn->disconnect();
To get messages you can use $data = $conn->processUntil('message');

Connecting PHP to Cloud MYSQL Google Apps

I am trying to connect my google app to a google cloud SQL instance, I have followed all the documentation and have read every page here I can find but no luck so far.
I am connecting using this -
<?php
$host = ":/cloudsql/<your-project-id>:<your-instance-name>";
$user = "root";
$password = " ";
$datbase = "cloudbooks";
mysql_connect($host,$user,$password);
mysql_select_db($datbase);
?>
The error I am getting is
Unable to find the socket transport "unix" - did you forget to enable it when you configured PHP?
Any help would be amazing!
First thing's last.. Do not use mysql_ instead use mysqli_ for all the reasons on this you can check this : Stackoverflow mysql_
Moving on from that, there is no reason you should think of connecting to a MySQL server any different just because of how its hosted. Cloud is a wonderfull Buzz word.. But its nothing new, its still just a host.
So you can use the following in your connection construction.
$host = "hostname // IP";
$user = "username";
$password = "password";
$datbase = "your_database";
There is actually some documentation also on this : google 'cloud' MySQL

Securely send password to LDAP server using PHP

What I am trying to do is set up a login screen. I collect the user's credentials and verify it using an ldap server before allowing the user to take a quiz.
<?php
session_start();
$user = $_POST['user'];
$domain = 'DOMAIN';
$password = $_POST['password'];
$ldapserver="ldap.example.server";
$ldapport=389;
$ldap = ldap_connect($ldapserver,$ldapport);
if ($bind = #ldap_bind($ldap,"{$user}#{$domain}", $password)){
$_SESSION["user"] = '$user';
header('Location: quiz.php');
}
else {
header('Location: login.html');
}
?>
When I use wireshark to sniff the packets, i can see the username and password clearly. Is there a way to bind to an LDAP server without sending the password in plain text? The site doesnt have https. The owner does not want to buy a SSL certificate, nor is he interest in a self-signed one.
Does your ldap server support ldaps and have a certificate? That would be the easiest way to do this and your site wouldn't need a certificate. You'd just change your code slightly. Assuming your server uses the default ldaps port:
$ldapserver = 'ldaps://ldap.example.server';
$ldapport = 636;

Cpanel API Access denied

I'm using XML api 2
$xmlapi = new xmlapi('MY IP Address');
$xmlapi->password_auth("root",'My Cpanel password');
$xmlapi->set_output("json");
$xmlapi->set_debug(1);
print $xmlapi->api2_query($account, "Email", "listpopswithdisk" );
But it's giving this error.
{"cpanelresult":{"apiversion":"2","error":"Access denied","data":{"reason":"Access denied","result":"0"},"type":"text"}}
How to resolve this error.
Check your port settings -
$xmlapi->set_port(2083); //2082 if not using secure connection

Services_Twitter Pear PHP code - OAuth direct messages suddenly stopped working

I have the following PHP code, which up to a week or so ago was working to send Twitter direct messages to a particular user. I now get "HTTP_OAuth_Exception: Unable to connect to tcp://api.twitter.com:80. Error #0: php_network_getaddresses: getaddrinfo failed: Name of service not known in /usr/share/pear/HTTP/OAuth/Consumer.php on line 257"
I've searched around and can't find that anything has changed with Twitter since it was working and the server configuration also hasn't changed. I tried using SSL in case Twitter suddenly required connection via SSL, but that gave basically the same error (except it said ssl and port 443).
I'm at a loss to see what's wrong and don't believe anything changed on my side. My code is based on the example in the Services_Twitter documentation (http://pear.php.net/package/Services_Twitter/docs/latest/Services_Twitter/Services_Twitter.html#var$oauth)
Any help would be greatly appreciated.
require_once 'Services/Twitter.php';
require_once 'HTTP/OAuth/Consumer.php';
$twitterto = 'xxxxxxxxxxxx';
$message='This is a test message';
$cons_key='xxxxxxxxxxxx';
$cons_sec='xxxxxxxxxxxx';
$auth_tok='xxxxxxxxxxxx';
$tok_sec='xxxxxxxxxxxx';
try {
$twitter = new Services_Twitter();
$oauth = new HTTP_OAuth_Consumer($cons_key,
$cons_sec,
$auth_tok,
$tok_sec);
$twitter->setOAuth($oauth);
// The error is raised on the following line.
$twitter->direct_messages->new($twitterto, $message);
$twitter->account->end_session();
} catch (Services_Twitter_Exception $e) {
echo $e->getMessage();
}

Categories