imap fecthing in php [duplicate] - php

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
PHP imap problems
why are some of the characters messed up when displayed;
here is my code
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
$emails = imap_search($inbox,'TEXT "$variable"');
if($emails) {
$output = '';
rsort($emails);
foreach($emails as $email_number) {
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,2);
$output.= '<div class="body">'.$message.'</div>';
}
echo $output;
}
the output for the email was getting =3 and other weird characters
file is edited, see the answer given,

the answer to this is to use this function
imap_qprint

Related

IMAP - in_reply_to always blank

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...

open email by php using imap giving me this error Message: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl}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

Php accessing the email inbox for email address

I needed to get the Email address from which Im getting/receiving emails in my Inbox! what should I do for this, I at this time have the following code
<?php
$mbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX", "address#gmail.com", "passw0rd")
or die("can't connect: " . imap_last_error());
$status = imap_status($mbox, "{imap.gmail.com:993/imap/ssl}INBOX", SA_MESSAGES);
if ($status) {
echo $status->messages;
}
?>
<?php
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'davidwalshblog#gmail.com';
$password = 'davidwalsh';
/* 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);
?>
link :Update code from
EDIT
subject - the messages subject
from - who sent it
to - recipient
date - when was it sent
message_id - Message-ID
references - is a reference to this message id
in_reply_to - is a reply to this message id
size - size in bytes
uid - UID the message has in the mailbox
msgno - message sequence number in the mailbox
recent - this message is flagged as recent
flagged - this message is flagged
answered - this message is flagged as answered
deleted - this message is flagged for deletion
seen - this message is flagged as already read
draft - this message is flagged as being a draft

Webmail access through PHP [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have Cpanel and domain. I can create email account by going to the email account option in Cpanel. My question is how can I create an email account in Cpanel from a php web application?
I want a proper guide to this.
Thanks in advance.
Please Check it out.I hope it will help you what you want.
http://www.zubrag.com/scripts/cpanel-create-email-account.php
Check this out. Its for gmail account.Configure for your account:
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'username#gmail.com';
$password = 'password here';
/* 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.= '<span class="date">on '.$overview[0]->date.'</span>';
$output.= '</div>';
/* output the email body */
$output.= '<div class="body">'.$message.'</div>';
}
echo $output;
}
/* close the connection */
imap_close($inbox);
I think this will help you.Thanks.razin223

IMAP Live/Constant Sync like in Gmail

In Gmail, new emails are displayed instantaneously without page refresh. I can retrieve my gmail emails using PHP and IMAP. How could I implement or add this instantaneous/constant sync without page refresh? Here is the basic code:
http://pastebin.com/ivfbMSZk
$inbox = imap_open($hostname,$username,$password,NULL,1) or die('Cannot connect to Gmail: ' . print_r(imap_errors()));
$emails = imap_search($inbox,'ALL');
if($emails) {
$output = '';
rsort($emails);
foreach($emails as $email_number) {
$message = imap_fetchbody($inbox,$email_number,1);
$output.= $message;
}
echo $output . "\n";
}
You would need something like the comet model, there are questions like this one rewarding this subject, on this, php works for light traffic only.

Categories