mai( ) with html
| From: | arch | Date: | Sat, 15 Feb 2003 15:03:07 +0000 |
| Subject: | mai( ) with html | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-135668@lists.php.net to get a copy of this message | ||
Hi,
I'm trying to send HTML in an email by using the mail( ) function. This is a
well documented and much talked about function, and I've already been
successful in sending regular text email and basic HTML. The twist is that I
want to first grab HTML from another server via HTTP, put this content into
a string, and then use mail( ) to send it to an address. I've been working a
whole day, and while the email does send, the message body is blank--no
HTML, no text, nothing.
Here's what I'm trying:
// this doesn't work. blank email body is received
$fp = fopen ("http://www.somesite.com",
"r");
$msg = "";
while($data= fread ($fp, 1024))
$msg .= $data;
mail($to, $subject, $msg, "MIME-Version: 1.0\r\nContent-Type: text/html;
charset=iso-8859-1\r\n"))
So, a file connection is made to some webpage on another server, and the
data is read into a variable, $msg. Note that the data IS successfully read,
as I've verified by echoing to the browser as well as writing to a local
file. When the data is used as the message of the email to be sent out, a
blank email body is received! However, if HTML is hardcoded into $msg
(instead of read in via an http connection), the email is sent perfectly,
and HTML is seen in the email body:
// this works fine
$msg = "<html><body>testing</body></html"; // this can be as complex
as you
like
mail($to, $subject, $msg, "MIME-Version: 1.0\r\nContent-Type: text/html;
charset=iso-8859-1\r\n"))
Can someone please help?