I'm writing an app that reads a couple of files (a text file and an html file) in off the server and builds a multipart email out of the two files. The text is used as the plain text alternative and the html is used as the html part for those email clients that support it.
I'm using file_get_contents() to read the contents of the two files into strings. The problem I'm having is that the resulting strings are containing the end of file characters (at least I think they are) and I need to strip those out. If I send the email with those end of file characters still in the strings, nothing in the email past the first end of file is sent.
So how do I strip those out so I can get the entire email to send?
Thanks,
Eric Stewart
removing end of file characters.
Moderator: General Moderators
-
clashingrocks
- Forum Newbie
- Posts: 1
- Joined: Fri Aug 26, 2005 11:48 am
You can use PHP's rtrim to remove characters from the end of the string. Here's a link for more information on the rtrim function:
http://us3.php.net/rtrim
http://us3.php.net/rtrim
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
i dont think get_file_contents() would read a .html (f.e.) and put .html on the end of the string, atleast it doesnt for me.
but if you knew the extension you want to strip just use substr($string, 0, -5), that would work for extensions such as .html.
i might be way off what you want here, if so, explain more
ps. i left this window open for about an hour sorry if about 50 other people have said same thing!
but if you knew the extension you want to strip just use substr($string, 0, -5), that would work for extensions such as .html.
i might be way off what you want here, if so, explain more
ps. i left this window open for about an hour sorry if about 50 other people have said same thing!
I'm not sure if the NUL byte is the problem here. Are you setting up all the normal MIME headers properly? If you want to send both the raw text and HTML versions, that will require setting up a multi-part email using MIME.
If the NUL byte really is the problem you could try just doing something like
to remove the final character.
If the NUL byte really is the problem you could try just doing something like
Code: Select all
$str=substr($str,0,-1);[SOLVED]
The rtrim() on the file extracted string solved the problem. The emails are now sent out with both the html and plain text version and work perfectly.
Thank you clashingrocks, jayshields, and nielsene for all your help.
Eric Stewart
Thank you clashingrocks, jayshields, and nielsene for all your help.
Eric Stewart