Jump to content

Help appending to and printing out an email from gmail


prdycool

Recommended Posts

Hello!

 

I should start by saying I don't really know what I'm doing, so please be patient with me. I know very little php but really want to implement this new system at work and have the help of a programmer friend (he understands reading the code but doesn't know how to do these things in php specifically since he hasn't used it much). I also apologize if this has been answered before, but I understand so little and have a very specific situation and have been unable to find anything to work for me. With that intro, here is the set up:

 

We sell stuff on eBay and get PayPal notification emails when someone has paid. We are trying to implement a new inventory system that does the following:

 

1. We receive the payment emails and using php I connect to gmail and get the unread messages (complete)

2. I trim out some of the encoding garble just getting the main message section (complete)

3. We parse the emails for the Item numbers (almost complete, might need some help with this)

4. We use a mysql query to ask the database what shelves the items are on (I have set up a table of the item numbers and shelves and should be able to handle this part)

5. Now things get tricky (I think). We want to take the mysql query result and append it to the end of the email and print out the email. However, I want to print the original email as seen on gmail with the PayPal formatting, not the edited plain text I was working with. We use the print out as a packing slip so we would like it to be the original, just with a line at the bottom that says the shelf number. The point of this is so the shipping department will just get a packing slip printout that also tells them where to get the item.

 

The first thing I am having problems with is the physical printing. The server with the code and database are on a network with the printer but I think I also need to install something (sudo apt-get install something) to get the printer functions to work. Then I don't know how to print a gmail email in its original form.  Then there is appending the shelf number to the end of the email and still having it print in the correct form.

 

Any help would be wonderful and I would be happy to share the code I have as we go along!

To start, you should look into the printer php functions:

 

http://us.php.net/manual/en/book.printer.php

 

As for the formatting, the email you are receiving is probably in HTML so the raw output would show tags instead of parsing it. You might be able to get around this by using the output buffering functions like ob_start() and ob_end_clean():

 

http://us2.php.net/manual/en/function.ob-start.php

http://us2.php.net/manual/en/function.ob-end-clean.php

Thanks for the tips, but I got ahead of myself it seems. I have been able to pull the item number out of the PayPal emails EXCEPT emails that have Chinese characters. When I pull those from gmail they are just a jumble of letters. Looking at the originals on gmail I found that most are charset windows-1252 but the ones with Chinese characters are utf-8. I tried iconv and mb_convert_encoding but it still appears as the jumble of letters. Can someone help me figure out how to convert these? I get the email body with imap_fetchbody grabbing section 1.1 or 1.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.