Need help with sending HTML formatted emails

Need help with sending HTML formatted emails

am 01.10.2007 06:16:56 von Big Moxy

Here is my code for formatting an HTML email. I know that spinning
through the $_POST array as I am isn't very pretty but it's a long
list so for now I'm using this approach. The problem is that despite
setting the Content-type the resulting email arrives in plain text.
Outlook 2003 is my email client and I receive HTML emails without a
problem.

Can someone please advise me on what I'm doing wrong?

$to_address = "to@mysite.com";
$from_address = "webmail@mysite.com";
$subject = "Evaluation Request";
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers.= "From: $from_address\r\n";
$message = "";
foreach ( $_POST as $key => $value ) {
$message.= "" . $key . "" . " " . ":" . " " . $value . "
>";
};
$_SESSION['sent_message'] = "Thank you for your request! Someone will
be contacting you soon.";
mail($to_address, $subject, $message, $headers);
header = ("location: index.php");

Thank you!
- Tim

Re: Need help with sending HTML formatted emails

am 01.10.2007 06:26:43 von Big Moxy

On Sep 30, 10:16 pm, Big Moxy wrote:
> Here is my code for formatting an HTML email. I know that spinning
> through the $_POST array as I am isn't very pretty but it's a long
> list so for now I'm using this approach. The problem is that despite
> setting the Content-type the resulting email arrives in plain text.
> Outlook 2003 is my email client and I receive HTML emails without a
> problem.
>
> Can someone please advise me on what I'm doing wrong?
>
> $to_address = "t...@mysite.com";
> $from_address = "webm...@mysite.com";
> $subject = "Evaluation Request";
> $headers = "MIME-Version: 1.0\r\n";
> $headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
> $headers.= "From: $from_address\r\n";
> $message = "";
> foreach ( $_POST as $key => $value ) {
> $message.= "" . $key . "" . " " . ":" . " " . $value . "
";
> };
>
> $_SESSION['sent_message'] = "Thank you for your request! Someone will
> be contacting you soon.";
> mail($to_address, $subject, $message, $headers);
> header = ("location: index.php");
>
> Thank you!
> - Tim

NEVER MIND! My emails are taking longer to arrive than expected.
However I received a plain text email after I had changed my code so
that the headers were set before creating the message and just assumed
there still was a problem. However after my post a new email arrived
an it was formatted as expected.

Re: Need help with sending HTML formatted emails

am 01.10.2007 08:09:55 von Tim Roberts

Big Moxy wrote:
>
>Here is my code for formatting an HTML email. I know that spinning
>through the $_POST array as I am isn't very pretty but it's a long
>list so for now I'm using this approach. The problem is that despite
>setting the Content-type the resulting email arrives in plain text.

What do you mean by that? Do you mean you see the HTML tags?

>Outlook 2003 is my email client and I receive HTML emails without a
>problem.

Most HTML emails come in as Content-Type: multipart/alternative with a
text/html section and a text/plain section. However, what you describe
should work. Have you tried wrapping the HTML with and tags?

> $message.= "" . $key . "" . " " . ":" . " " . $value . "
>>";

Why would you do it that way, instead of the much more efficient:
$message.= "$key : $value
";
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.