Re: mail() sending in html format (or not)



paul wrote:
steve wrote:

actually the answer *is* easy...the problem is in your mail headers and/or your boundry settings (even to the detail of how many \r\n's there are that separate each section. and, if you delete my dynamic html crap, you'd end up with only about 10 lines of pertanent code...much less confusing.

let me know if you need further assistance or of your progress.


Thanks,
I tried to boil it down to something simple here. The main thing I don't get is you used iisMail() and I don't know what that is so I just used mail(), which didn't work <g>.


"Warning: mail() expects at least 3 parameters"



Well, I just tried it like this:

mail($emailTo, "Important email for you", $text, $mail);

And that worked, though the resulting email looked blank but when I viewed it in notepad, most of the formatting looked roughly correct. I'll just paste that and maybe give a clue. I tried sending myself a simple mozilla composed html/plain text email and it looked 'similar'.

X-UIDL: UID10718-1099634831
X-Mozilla-Status: 0001
X-Mozilla-Status2: 00000000
Return-Path: <anonymous@xxxxxxxxxxxxxx>
Received: from blahblahblah...
Received: blahblahblah...
Delivered-To: me@xxxxxxxxxx
Received: blahblahblah...
Date: 30 Jun 2005 14:05:07 -0000
Message-ID: <20050630140507.65574.qmail@xxxxxxxxxxxxxx>
To: me@xxxxxxxxxx
Subject: Important email for you
MIME-Version: 1.0
FROM: Automated Email <TheMachine@xxxxxxxxxxx>
TO: me@xxxxxxxxxx
CC: them@xxxxxxxxxxxxxx
Subject: Important email for you

Content-Type: multipart/alternative;
X-Scanned-By: MIMEDefang 2.51 on 66.226.64.15

boundary=""





--

Content-Type: text/plain; charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable







message body here





--

Content-Type: text/html; charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable




<html> <style> </style> <body> <table><tr><td>



message body here

</td></tr></table>


</body> </html>




-- End --







message body here


-------






It seems you were somehow building the $html & $text separately, then added the $text into the $html preserving a plain text and html version to send.


"\r\n" must be some special line break???

<?
function html_mail()
{
  global $emailTo;
  global $emailCC;
  $html     = '
            <html>
              <style>
              </style>
              <body>
              ';
  $text     = '';
    $html   .= '<table><tr><td>';
    $text   .= "\r\n\r\n" . "message body here" . "\r\n";
//add content here
    $html   .= $text
    $html   .= '</td></tr></table>'
                . "\r\n";
  $html .= "
              </body>
            </html>
           ";
  $mail     = "MIME-Version: 1.0\r\n";
  $mail    .= "FROM: Automated Email <TheMachine@xxxxxxxxxxx>\r\n";
  $mail    .= "TO: "  . $emailTo . "\r\n";
  $mail    .= "CC: "  . $emailCC  . "\r\n";
  $mail    .= "Subject: Important email for you \r\n";

//  $mail    .= "Content-Type: multipart/related;
//boundary=\"$related\"\r\n\r\n\r\n";
//  $mail    .= "--$related\r\n";

  $mail    .= "Content-Type: multipart/alternative;
boundary=\"$boundry\"\r\n\r\n\r\n";
  $mail    .= "--$boundry\r\n";
  $mail    .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
  $mail    .= "Content-Transfer-Encoding: quoted-printable\r\n\r\n";
  $mail    .= $text . "\r\n\r\n";
  $mail    .= "--$boundry\r\n";

$mail .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$mail .= "Content-Transfer-Encoding: quoted-printable\r\n\r\n";
$mail .= $html . "\r\n\r\n";
// $mail .= "--$boundry--\r\n\r\n";
// $mail .= "--$related\r\n";
// $mail .= "Content-Type: image/jpeg\r\n";
// $mail .= "Content-ID: logo\r\n";
// $mail .= "Content-Disposition: attachment; filename=\"logo.jpg\"\r\n";
// $mail .= "Content-Transfer-Encoding: base64\r\n\r\n";
// $mail .= $image . "\r\n\r\n";
// $mail .= "--$related--\r\n\r\n";
$mail .= "-- End --\r\n";
// iisMail($mail);
mail($mail);
}


//now use the function
  $emailTo = "them@xxxxxxxxxxxxxx";
  $emailCC = "me@xxxxxxxxxx";
  html_mail()
?>
.



Relevant Pages

  • Re: HTML vs XHTML
    ... here recommending that authors stick to HTML, ... layout to make them completely separate independently carried units. ... Microsoft brought its XSLT model in accordance with W3C specs, ...
    (comp.infosystems.www.authoring.html)
  • Re: Is it better to echo or leave as html?
    ... > Don't forget that a Template Engine is not supposed to separate PHP code ... > from HTML but business logic from presentation logic. ... I think Template engine purpose _is_ to separate html from code. ...
    (comp.lang.php)
  • Re: Encapsulation and js, html, css
    ... a nice object/constructor without worrying, ... Separate interface and implementation. ... Put css to a separate file. ... Between css and html there seems to be no serious problems: ...
    (comp.lang.javascript)
  • Re: "Best" coding practice?
    ... > The goal is not to seperate HTML and PHP, ... Using a loop inside your HTML is not a bad thing, ... MVC to separate presentation logic and bussines logic. ... and stuffing too much into template in order to handle ...
    (comp.lang.php)
  • Re: "Best" coding practice?
    ... > The goal is not to seperate HTML and PHP, ... Using a loop inside your HTML is not a bad thing, ... MVC to separate presentation logic and bussines logic. ... and stuffing too much into template in order to handle ...
    (alt.php)