Link to home
Start Free TrialLog in
Avatar of MarthaJ Sayers
MarthaJ Sayers

asked on

Php and email messages

I am using Php - v 5.6.25 and using localhost. I am extracting data from the body of the email message and I know that it could be sent as plain text or HTML.
Is it possible to detect if it is text or HTML and convert to plain text ??
Thank you so much...
Avatar of David Favor
David Favor
Flag of United States of America image

Simple solution is to run all your messages through the html2text tool.

Any text will pass through unaffected. Any HTML will be converted to text.
Avatar of MarthaJ Sayers
MarthaJ Sayers

ASKER

Thank you for responding. There are quit a few of them. A bit confusing. I am using PHP, the page will be eventually be executed as a scheduled task. What one do you recommend ?? would I have to load on server ??
ASKER CERTIFIED SOLUTION
Avatar of Phonebuff
Phonebuff
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
1) Thank you for responding.

You're welcome!

2) There are quit a few of them. A bit confusing.

Unsure what you mean by "quite a few of them". You'll have to first define what "them" might mean.

Maybe you mean html2text type tools, or files you're processing.

More context is required to answer.

3) I am using PHP, the page will be eventually be executed as a scheduled task. What one do you recommend ?? would I have to load on server ??

No real clue what you're asking here.

Maybe you're asking about processing HTML to text inside PHP, which is possible + not recommended.

4) What you asked was how to convert HTML to text.

For this you'll generally use a conversion tool like html2text, run from PHP with your file(s) as input.

How you do this is up to you. Only you know your code.

Generally the way I do this is to run all files in question through html2text into other files... such as...

html2text < infile > outfile

Open in new window


This guarantees, in your case, all outfile(s) are text, then you'll perform other actions on the text files produced.
Thank you all for responding and I apologize for not replying sooner and for being too glib in my question.
I live way out in the country, work at home and we had a power outage.
I will clarify:

2. There are several html2text type tools. I was wondering what the best was to use.
3. The page I am creating using PHP will be executed a as unattended task on server.
4. I know how to strip HTML and convert to text but I thought there might be an easier way
other then a third party tool. I too, do not executing 3rd party tools of that nature,  from inside coding


I understand about the Content-Type: info  - helps alot with some tasks with emails.
And I like it causes it is helpful to know the details of how to use and its usefulness.
But yes, you are very right about all the info to google.

 You both have been helpful.
I decided not to use a third-party tool.
Thank you both very much.
I thank you both. Be safe and well.