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...
Chat / IMHTMLPHP

Avatar of undefined
Last Comment
MarthaJ Sayers

8/22/2022 - Mon
David Favor

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

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
David Favor

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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
MarthaJ Sayers

ASKER
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.
MarthaJ Sayers

ASKER
I thank you both. Be safe and well.