I want to receive the mails from gmail using imap. I have used the code $connection_result = $imap->connect('{imap.gmail.com:993/imap/ssl}INBOX', 'xxxxxxx#gmail.com', 'xxxxxx');
It works in the local xampp but if host in my server, its giving error as
Cannot connect to Mail: Can't connect to gmail-imap.l.google.com,993: Network is unreachable
How to use in server. Anyone can help?
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'example#gmail.com';
$password = 'example';
$inbox = imap_open($hostname,$username ,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
$emails = imap_search($inbox,'ALL');
if($emails) {
$output = '';
rsort($emails);
foreach($emails as $email_number) {
$overview = imap_fetch_overview($inbox,$email_number,0);
$output.= 'Name: '.$overview[0]->from.'</br>';
$output.= 'Message ID: '.$overview[0]->message_id.'</br>';
$output.= 'Subject: '.$overview[0]->subject.'</br>';
$output.= 'UID: '.$overview[0]->uid.'</br>';
$output.= '<hr/>';
}
echo $output;
}
imap_close($inbox);
Related
I want to pair a reply with the original message.
I am connecting to a gmail account like so:
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'somebody#gmail.com'
$password = 'password';
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
$emails = imap_search($inbox,'UNSEEN');
$max_emails = 3;
if($emails) {
rsort($emails);
foreach($emails as $email_number) {
$overview = imap_fetch_overview($inbox,$email_number,0);
if($count++ >= $max_emails) break;
}
}
When an email in the inbox is a reply, the [in_reply_to] field appears within imap_fetch_overview, so it knows it's a reply, however this field is always blank.
How can I pair a reply to the sent message?
Ignore this...
I was displaying results like so:
print_r($overview);
When doing this instead:
var_dump($overview);
The information is there.
Not sure why that is...
I'm using php imap functiona to get mail content.
Following is my code:
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = $_REQUEST['email'];
$password = $_REQUEST['pwd'];
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
$emails = imap_search($inbox,'ALL');
if($emails) {
$output = '';
rsort($emails);
$i = 0;
foreach($emails as $email_number)
{
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_qprint(imap_body($inbox, $email_number));
}
}
Displaying html data as it is in my mail body along with some raw data. How can I remove this.
--94eb2c03a0feeaad70054df6411a
Content-Type: text/plain; charset=UTF-8; format=fowed; delsp=yes
Content-Transfer-Encoding: base64
PT09IEZpbmFuY2UgLSAxIG5ldyByZXN1bHQgZm9yIFthbGliYWJhXSA9PT0NCg0KDQo8aHR0cHM6
Ly93d3cuZ29vZ2xlLmNvbS91cmw/cmN0PWomc2E9dCZ1cmw9JmN0PWdhJmNkPUNBRVlBQ29UTnpN
ek1EUTBPREE0TVRnNU9EWTJPVFl5TkRJYVptVXpOR0psT0Rnd00yTmpPREF6WXpwamIyMDZaVzQ2
VlZNJnVzZz1BRlFqQ05GMXNIbGsyejlRSXgyOGp0dmZuR1BfVWxraWZBPg0KDQoNCj09PSBOZXdz
IC0gMTAgbmV3IHJlc3VsdHMgZm9yIFthbGliYWJhXSA9PT0NCg0KQWxpYmFiYSdzIFN0cm9uZyBH
cm93dGggUmF0ZSBJcyBVbmRlcmFwcHJlY2lhdGVkDQpTZWVraW5nIEFscGhhDQpBbGliYWJhJ3Mg
aGlzdG9yaWNhbCBncm93dGggcmF0ZSBpcyBhbiBhdmVyYWdlIG9mIDUwJSBmb3IgdGhlIGxhc3Qg
Zml2ZQ0KeWVhcnMsIHdoaWNoIGlzIG5vdGhpbmcgc2hvcnQgb2Ygc3BlY3RhY3VsYXIuIE1hbmFn
ZW1lbnQgaXMgYWNjZWxlcmF0aW5nIHRoZQ0KLi4uDQo8aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS91
cmw/cmN0PWomc2E9dCZ1cmw9aHR0cHM6Ly9zZWVraW5nYWxwaGEuY29tL2FydGljbGUvNDA2NDc1
NS1hbGliYWJhcy1zdHJvbmctZ3Jvd3RoLXJhdGUtdW5kZXJhcHByZWNpYXRlZCZjdD1nYSZjZD1D
QUVZQUNvVE56TXpNRFEwT0RBNE1UZzVPRFkyT1RZeU5ESWFabVV6TkdKbE9EZ3dNMk5qT0RBell6
cGpiMjA2Wlc0NlZWTSZ1c2c9QUZRakNOSEFPUTlfSHZodHNvOVlwbnNuTk02VDdvb011Zz4NCg0K
VGhlIG5leHQgZ3JlYXQgQ0VPIGNvdWxkIGJlIGEgcm9ib3QsIEFsaWJhYmEncyBKYWNrIE1hIHNh
eXMNClVTQSBUT0RBWQ0KSmFjayBNYSwgdGhlIGZvdW5kZXIgYW5kIGNoYWlybWFuIG9mIENoaW5l
c2UgZS1jb21tZXJjZSB0aXRhbiBBbGliYWJhLA0KcHJlZGljdHMgImEgcm9ib3Qgd2lsbCBsaWtl
bHkgYmUgb24gdGhlIGNvdmVyIG9mIFRpbWUgbWFnYXppbmUgYXMgdGhlIGJlc3QNCi4uLg0KPGh0
dHBzOi8vd3d3Lmdvb2dsZS5jb20vdXJsP3JjdD1qJnNhPXQmdXJsPWh0dHBzOi8vd3d3LnVzYXRv
ZGF5LmNvbS9zdG9yeS90ZWNoL3RhbGtpbmd0ZWNoLzIwMTcvMDQvMjQvbmV4dC1ncmVhdC1jZW8t
Y291bGQtcm9ib3QtYWxpYmFiYS1qYWNrLW1hLzEwMDgzNjMzOC8mY3Q9Z2EmY2Q9Q0FFWUFTb1RO
ek16TURRME9EQTRNVGc1T0RZMk9UWXlORElhWm1Vek5
Any suggestions please.
Everything works fine, but i need one more function. On every newmail, in same line i need button "OWNER", so when user input his inicials in that field, field will be locked so anybody can know who own which mail.
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'X';
$password = 'X';
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'ALL');
/* if emails are returned, cycle through each... */
if($emails) {
/* begin output var */
$output = '';
/* put the newest emails on top */
rsort($emails);
/* for every email... */
foreach($emails as $email_number) {
/* get information specific to this email */
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,2);
/* output the email header information */
$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
$output.= '<span class="from">'.$overview[0]->from.'</span>';
$output.= '</div>';
}
echo $test , $test , $output;
}
imap_close($inbox);
I am trying to open the email messages by php using imap method but it give me an error Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX and this is my code
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'nohamedtemraz92#gmail.com';
$password = '0129799169mohamed';
/* try to connect */
$inbox = imap_open($hostname,$username ,$password) or die('Cannot connect to Gmail: ' imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'ALL');
/* if emails are returned, cycle through each... */
if($emails) {
/* begin output var */
$output = '';
/* put the newest emails on top */
rsort($emails);
/* for every email... */
foreach($emails as $email_number) {
/* get information specific to this email */
$overview = imap_fetch_overview($inbox,$email_number,0);
$output.= 'Name: '.$overview[0]->from.'</br>';
$output.= 'Email: '.$overview[0]->message_id.'</br>';
}
echo $output;
}
/* close the connection */
imap_close($inbox);
Try this:
$hostname = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
$inbox = imap_open($hostname,$username ,$password) or die('Cannot connect to Gmail: ' imap_last_error());
{imap.gmail.com:993/imap/ssl}INBOX
working for me but you have to enable 'Access for less secure apps' on account security or you can try live email account
I wrote a simple 3 line code for connecting to gmail through imap-php.
i am using 000webhost for running it.
but when i try to open it, it keeps on loading and after some times shows "Problem loading page" or "No data recieved", as if gmail servers are not responding!!
Any suggestions whats the problem?
$hostname = "{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Inbox";
$username = 'abc#gmail.com';
$password = "abc123";
$inbox = imap_open($hostname,$username,$password)or die('Cannot connect to Gmail: ' . imap_last_error());
$server_name = "imap.gmail.com";
$account_name = "email#mydomain.com";
$account_pwd = "my_account_password";
$inbox = imap_open("{".$server_name.":993/imap/ssl/novalidate-cert}INBOX",
$account_name, $account_pwd) OR error_imap_mail("Unable To Open Imap
Connection","Imap Failure",imap_errors());
function error_imap_mail($subject,$messagetext,$errors) {
global $report_email;
$mailfrom = "support#mydomain.com";
$mailsubject = "$subject";
$mailbody = "$messagetext\n\n";
if (count($errors) >0) {
if (substr($errors[0],0,8) <> "[IN-USE]") {
array_reverse($errors);
foreach ($errors as $key=>$value) {
$mailbody .= "\nErr No.".$key." Error:".$value;
}
foreach ($report_email as $value) {
mail($value, $mailsubject, $mailbody, "From: $mailfrom");
}
}#if (substr($err_array[0],0,8) <> "[IN-USE]") {
}#if (count($errors) >0) {
exit;
}
Get your script to send you the errors if it fails to connect.
Have you turned IMAP on in the account setting in Gmail?
Try this:
$hostname = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
$username = 'abc#gmail.com';
$password = "abc123";
$inbox = imap_open($hostname,$username,$password)or die('Cannot connect to Gmail: ' . imap_errors());
Also make sure you enable IMAP for you account via GMail settings.