RE: MAIL() help needed :-(

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi there,

Thanks for the help, I've sorted it out now - stupid me :-)  You know what
it's like sometimes, you work that hard on different things that something
which should be really simple just goes over your head - well, it does mine
anyway :-)

Very much appreciated.

Chris

Hey Chris,

Probably a good idea would be to read the email RFC.

I'd say that you're trying to send a Multi-part MIME email, but not
formatting it correctly. You even forget to include your 'simple' (plain
text) message in the email body. SO if you were formatting it correctly, and
your friend is only viewing plain text, you won't see anything.

Here's the basic structure of a Multi-part MIME email:

---- begin quote ----
From:  Persons Name <address@xxxxxxxxxx>
MIME-Version: 1.0
Content-type: multipart/alternative; boundary=mime_seperator
X-Mailer: PHP/5.0.0
This is a multi-part message in MIME format.

--mime_seperator
Content-type: text/plain;    charset=us-ascii
Content-Transfer-Encoding: 7bit
This is the plain text part of the email.

--mime_seperator
Content-type: text/html;    charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
<HEAD><TITLE>Email Title</TITLE></HEAD>
<BODY>
HTML Email  in here
</BODY>
</HTML>

--mime_seperator-

---- end quote ----


A few notes for you:

1. "This is a multi-part message in MIME format." begins the email body. (ie
it's not a header)
2. Most of the headers need \r\n as a newline. \n won't do. (Checkout the
code below to see where to use \r\n and where to use \n)
3. You need a mime seperator to begin each section of the email. it should
be preceded by -- each time. You should end the email with the mime
seperator preceeded with -- AND suffixed with -. You can use pretty much
anything for the seperator. There may be a restriction on which characters
you can use.
4. This does not cover attachments. If you want to send attachments in the
email, you need to do some further research.

Official EMail RFCs:
http://www.ietf.org/rfc/rfc2822.txt
http://www.ietf.org/rfc/rfc1341.txt

Here's a great tutorial at "PHP Builder":
http://www.phpbuilder.com/columns/kartic20000807.php3


Here's how I do the above email:

<?
  $myname="My Name";
  $my_email="foo@xxxxxxxxxxxxx";
  $username="Person's Name";
  $user_email="<someone@xxxxxxxxxx";
  $stamp=time();
  $subject="General Subject";
  $content_boundary="MYDOMAIN_$stamp";
  $extra_headers="From: $myname <$my_email> \r\nMIME-Version:
1.0\r\nContent-type: multipart/alternative;
boundary=\"$content_boundary\"\r\nX-Mailer: PHP/".phpversion();
  $start_html="Content-type:
text/html;\tcharset=\"us-ascii\"\nContent-Transfer-Encoding: 7bit\n\n";
  $start_text="Content-type:
text/plain;\tcharset=\"us-ascii\"\nContent-Transfer-Encoding: 7bit\n\n";
  $message="This is a multi-part message in MIME format.\r\n\r\n";
  $message.="--".$content_boundary."\r\n".$start_text;
  $message.="Plain text email.\r\nA new line\r\n\r\nTwo new lines follwed by
some more text."
  $message.="--".$content_boundary."\r\n".$start_html;
  $message.="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01
Transitional//EN\">\r\n<HTML>\r\n<HEAD><TITLE></TITLE>\r\n</HEAD>\r\n<BODY>\
r\n";
  $message.="Message body in here";
  $message.=\r\n</BODY>\r\n</HTML>";
  $message.="--".$content_boundary."-\r\n";
  mail($username."<".$user_email.">", $subject, $message, $extra_headers);
?>

Hope this helps.

Collin

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux