I am creating a web app that accepts input of news items (title, article, url). It has a page news.php
which creates a summary of all news items inputted for specified dates, like so:
News
4/25/2010
Title 1
[URL 1]
Article 1
Title 2
[URL 2]
Article 2
and so on...
I have two other pages, namely preview.php
and send.php
, both of which call news.php through a file_get_contents()
call.
Everything works fine except when the URL contains spaces. During Preview, the urls get opened (FF: spaces are spaces, Chrome: spaces are %20). However, during Send, when received as emails, the urls don't get opened, because the spaces are converted into + signs.
For example:
- Preview in FF: http://www.example.com/this is the link.html
- Preview in Chrome: http://www.example.com/this%20is%20the%20link.html
- Viewed as email in both browsers: http://www.example.com/this+is+the+link.html
Only #3 doesn't work (link doesn't get opened).
Why are the spaces in the urls correct (spaces or %20) when previewed, but incorrect (+) when received in the emails, when in fact, the same page is generated by the same news.php?
Any help appreciated :)
EDIT:
preview.php:
$HTML_version = file_get_contents('news.php');
echo $HTML_version;
send.php
$HTML_version = file_get_contents('news.php');
$body = "$notice_text
--$mime_boundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
$TEXT_version
--$mime_boundary
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
$HTML_version
--$mime_boundary--";
//some other code here to send the email
news.php:
<a href="<?php echo $url ?>">attachment</a>
//the $url there contains spaces