I need to read emails from gmail but i cant connect to gmail pop3 server.
Can anyone help me here ?
Here the code:
$pop3 = new POP3;
$pop3->server = 'pop.gmail.com';
$pop3->user = 'username';
$pop3->passwd = 'password';
$pop3->debug = true;
$pop3->pop3_connect()
The result:
Warning: fsockopen() [function.fsockopen]: unable to connect to pop.gmail.com:110 (Connection timed out) in /public_html/cron/pop3.php on line 64
Thanks
According to this page (connecting to Gmail using Outlook Express), you have to use port 995 for POP3 access to Gmail, and furthermore, SSL must be enabled.
Wikipedia also states this:
E-mail clients can encrypt POP3 traffic using Transport Layer Security (TLS) or Secure Sockets Layer (SSL). A TLS/SSL connection is negotiated using the STLS command. Some clients and servers, like Google Gmail, instead use the deprecated alternate-port method, which uses TCP port 995 (POP3S).
I'm not sure if it will help you, but GMAIL has an ATOM feed. I wrote a PHP script to download the Atom Feed, using CURL, so that I could check my email on my antiquated cell phone that only supported very simple HTML. So, depending on what you want to do, it might be easier to download and process the ATOM feed than it is to connect to the POP server.
I don't know what class you're using -- but for instance, using Daniel Lemos' package is shown below. The key is choosing the right port (995), and the right encryption method (TLS set to true for whatever pop3 package you are using). For example, you could use something like the below to initiate the connection. Not a big fan of how this class is architected, or the sample code (lot of nested if statements), but it does the job.
$pop3=new pop3_class();
$apop=0;
$pop3->authentication_mechanism="USER";
$pop3->debug=0;
$pop3->html_debug=1;
$pop3->join_continuation_header_lines=1;
$pop3->hostname = "pop.gmail.com";
$pop3->port = 995; // The port that gmail uses...
$pop3->tls = 1; // This is encryption
$user = "someuser";
$password = "some password";
if( !empty($error=$pop3->Open()) ){
die( "Something terrible happened..." );
}
$pop3->Login($user,$password,$apop);
I think there are two easy options to your email:
Cron atom feed like Kibbee says. But then you will have a little delay between when message was sent and when you fetch it.
Use http://smtp2web.com/ which will post your email to your website which means a lot shorter delay. Offcourse privacy should not be crucial, because your mail will pass through intermediate.
Related
I am using Laravel-imap package (https://github.com/Webklex/laravel-imap) to fetch emails using imap.
I'm able to make a successful connection, able to fetch folders and emails, all set in that part.
However, I need to ignore drafted emails but I'm not able to detect that if a message is draft using code because email objects seem to have similar properties. I am testing using my Gmail account imap settings.
Here is the code I'm using. Any kind of help would be appreciated. Thanks
$oClient->connect();
$aFolder = $oClient->getFolders();
foreach($aFolder as $oFolder){
$aMessage = $oFolder->messages()->all()->get();
/** #var \Webklex\IMAP\Message $oMessage */
foreach($aMessage as $oMessage){
print_r($oMessage);
}
}
my application use piwik for statistics. when I config the mail section. something wrong happen. the config is like this:
[mail]
transport = "smtp"
port = "587"
host = "smtp.qq.com"
type = "Login"
username = "username#qq.com"
password = "*********"
encryption = "tls"
and when transfer a mail the error information is like this:
An error occurred while sending 'PDF Email Report -
1.2016-11-15.2.zh-cn.pdf' to *******#qq.com. Error was 'mail from address must be same as authorization user'
and I google with this info , but nothing I found work fine.
I guess there was somewhere I can put the address from as I do before. But I don't find the place.
Could someone tell something about this question, thanks a lot.
I have handle this question. The solution is add a line in config/config.ini.php [General] code section.
noreply_email_address = username#qq.com
I don't know how it work. but obviously, it work.
Hope this solution can help someone !
I want to collect data from email to mysql database using php.
If some one is sent a mail to their mail account to my mail id. I want that mail information to store in my database. for further operation. It is possible in PHP because I saw this feature in one hosting support application Kayako Fusion which developed by PHP.
So plese give some information to do this task.
If you want to parse with PHP the best way is to use a 3rd party API to revive the email and then send it to your PHP script with a HTTP Post.
I'd recommend using either sendgrid.com or mailgun.com
Both of these services will parse the email and send you the information in a http POST that you can then insert into mysql. API docs for both: MailGun Incoming Parse API / SendGrid Incoming Parse API
You can use the imap functions, for example:
<?php
$imap = imap_open("{server.example.com:143}INBOX" , 'login' , 'password');
if( $imap ) {
//Check no.of.msgs
$num = imap_num_msg($imap);
//if there is a message in your inbox
if( $num >0 ) {
//read that mail recently arrived
$the_message = imap_body($imap, $num);
//Do the stuff with $the_message
}
//close the stream
imap_close($imap);
}
You'll have to setup a cronjob (scheduled task on Windows) that connects to the Exchange or POP server, retrieve's all new emails sinds the last run and insert them into the DB.
In case of a POP mail server(I think POP will be easier), there is a comment here with all functions you need right -> here. If that doesn't work, try Googling for "PHP POP wrapper" or something similar.
In case of a Microsoft Exchange server, you'd have to use a PHP Exchange wrapper, found one here for you.
Goodluck!
You can pipe your email to a php script and then extract each part of email and store it in data base.
check this example
when you get content of email you can do what ever you want
My idea is to integrate a live support chat on a website. The users text is send with xmpphp to my jabber client with the jabberbot sender id and if I answer, the jabber bot, takes my answer and transfers the text to the user.
There is only one problem. How do I separate different users or different chats? I don't want all users to see the answer, but the user who asks. Is there a kind of unique chat id or another possibility, that I might just missed?
User => Website => Chatbot => me
I want to answer and send it back to the user, but how can I find out the correct user from my answer?
Last time I have to solve this problem I used this architecture:
Entlarge image
The Webserver provides an JavaScript / jQuery or flash chat.
After chat is started, the client ask the server all 1 Second for new Messages.
Alternative for 1 Sec Polling
If that is to slow for you, have a look at websockets.
http://martinsikora.com/nodejs-and-websocket-simple-chat-tutorial
http://demo.cheyenne-server.org:8080/chat.html
But Websockets could no provided by php. There for you need to change php + apchache agaist node.js or java.
Plain HTTP PHP Methode
In PHP you will connect to the PsyBnc with is polling the messages from the supporter for you.
The PsyBnc is an IRC bot.
The reason why don't directly connect to XMPP or BitlBee is that those protocols don't like the flapping connect, disconnect from PHP. Because you can not keep the session alive, you need something that is made for often and short connects. This is the PsyBnc.
I would use something like this:
http://pear.php.net/package/Net_SmartIRC/download
<?php
session_start();
$message = $_GET['message'];
$client_name = $_GET['client_name'];
if (empty($_SESSION['chat_id'])) {
$_SESSION['chat_id'] = md5(time(). mt_rand(0, 999999));
}
if (empty($_SESSION['supporter'])) {
// how do you select the supporter?
// only choose a free?
// We send first message to all supporter and the first who grapped got the chat (where only 3 gues)
}
$irc_host = "127.0.0.1";
$irc_port = 6667; // Port of PsyBnc
$irc_password = "password_from_psy_bnc";
$irc_user = "username_from_psy_bnc";
include_once('Net/SmartIRC.php');
class message_reader
{
private $messages = array();
public function receive_messages(&$irc, &$data)
{
// result is send to #smartirc-test (we don't want to spam #test)
$this->messages[] = array(
'from' => $data->nick,
'message' => $data->message,
);
}
public function get_messages() {
return $this->messages;
}
}
$bot = &new message_reader();
$irc = &new Net_SmartIRC();
$irc->setDebug(SMARTIRC_DEBUG_ALL);
$irc->setUseSockets(TRUE);
$irc->registerActionhandler(SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^' . $_SESSION['chat_id'], $bot, 'receive_messages');
$irc->connect($irc_host, $irc_port);
$irc->login($_SESSION['chat_id'], $client_name, 0, $irc_user, $irc_password);
$irc->join(array('#bitlbee'));
$irc->listen();
$irc->disconnect();
// Send new Message to supporter
if (!empty($message)) {
$irc->message(SMARTIRC_TYPE_QUERY, $_SESSION['supporter'], $message);
}
echo json_encode(array('messages' => $bot->get_messages()));
Connect the support instant messanger to PHP
We have allready an IRC connection to the PsyBnc, now we need to send messages from IRC to ICQ, XMPP, GOOGLE TALK, MSN, YAHOO, AOI...
Here for is a nice solution named BitlBee.
BitlBee offers an IRC Server with can transfer message from and to nearly all instant messager protocols. By aliasing those accounts. For example you need for your system only 1 Server account at google talk, icq ... and at all your supporter to the buddylist of those accounts. Now BitleBee will provide your boddylist as an irc chat.
Your requirements are rather confusing. As Joshua said, you don't need a Jabber bot for this. All you need is a Jabber server - which you should already have. What you do is, you create a volatile user account sessionid#*yourdomain.com* whenever the chat feature is used and then you can just reply to any incoming message like normal while your website client can fetch the messages meant for it whenever.
Alternatively you could create one user account - qa#yourdomain.com - and use XMPP resource identifiers for the routing part. XMPP allows for something like qa#yourdomain.com/*sessionid* and you should be able to tell your XMPP library to only query a specific resource. Most XMPP client software will also reply to a specific resource by default and open a new conversation when applicable. This method is less "clean" than the first, but it would work somewhat better if you can't arbitrarily create user accounts for some reason.
I don't know what XMPP server you are using, but you could also try the Fastpath plugin and webchat for Openfire. Which is meant to provide a support team service over XMPP.
That being said, your question itself seems to imply nothing more than the standard chat feature of XMPP, which is between two users. It just means that the support person has a unique chat with each user asking a question. No other user will see that conversation.
I've written code about sending a verification mail to users who have registered !
But the thing is when i run the .php file in browser it says, not able to send the confirmation mail.
Someone told me that you need a server(domain) to send confirmation mail, it can't be sent using LOCALHOST.
Can i send confirmation mail from LOCALHOST ?? Any-way ??
If not, then tell me where can i get a FREE domain(for testing) where i can upload my .php files and send confirmation mail ??
If you're running the script from a developer server at home, you're most likely having problems with your ISP having blocked port 25.
What I would recommend you to do is use a Transactional Email service such as:
AlphaMail
PostageApp
Mandrill
Why?
Has HTTP API support (runs on port 80/443, so no ISP blocking). I.e. easy to run from home.
Future-proof. You don't have to think about hosting your own SMTP-infrastructure. Scaling it once your sendings increase.
You don't have to think about delivery. Being blocked because the IP you are sending from isn't whitelisted, the list goes on.
Statistics. Let's you track Total Sent/Clicks/Opens/Bounces.
How?
Since I am one of the developers behind AlphaMail, I of course recommend you to use it (but not only because I'm one of the developers behind it, but because it's great! :)). And since you're using PHP, it's easy to get going with the AlphaMail PHP-client:
include_once("comfirm.alphamail.client/emailservice.class.php");
$email_service = AlphaMailEmailService::create()
->setServiceUrl("http://api.amail.io/v1")
->setApiToken("YOUR-ACCOUNT-API-TOKEN-HERE");
$person = new stdClass();
$person->userId = "1234";
$person->firstName = "John";
$person->lastName = "Doe";
$person->dateOfBirth = 1975;
$response = $email_service->queue(EmailMessagePayload::create()
->setProjectId(12345) // Your AlphaMail project (determines template, options, etc)
->setSender(new EmailContact("Sender Company Name", "from#example.com"))
->setReceiver(new EmailContact("Joe Doe", "to#example.org"))
->setBodyObject($person) // Any serializable object
);
Another great thing with AlphaMail is that it separates logic from design. So you never have to bloat your code with ugly non-standard (email) HTML again. And once you need to change things it's no digging in code, just log into the AlphaMail Dashboard and edit your template immediately. Also, the templates are built using the simple template language Comlang, so they are highly personalizable.
<html>
<body>
<b>Name:</b> <# payload.firstName " " payload.lastName #><br>
<b>Date of Birth:</b> <# payload.dateOfBirth #><br>
<# if (payload.userId != null) { #>
Sign Up Free!
<# } else { #>
Sign In
<# } #>
</body>
</html>
You can use sendmail , smtp or some other services like Amazon SES . Amazon Simple email service provides sandbox feature with free of cost (but you need credit card to use its service) and it can easily configured into your localhost.