Php and email messages

MarthaJ Sayers
MarthaJ Sayers used Ask the Experts™
on
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...
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

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

Author

Commented:
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 ??
So, I am really not sure what you are attempting to do as you are somewhere mixing terms..

But the magic for what I think you want to do should be based on the Content-Type: in the SMTP header.   text/plain or text/html.

A little google Foo should give you any number of suggestions depending on what you are attempting to accomplish.

-----------------
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

David FavorFractional CTO
Distinguished Expert 2018

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

Author

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

Author

Commented:
I thank you both. Be safe and well.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial