Web Hosting Forum | Lunarpages
News: July 14, 2008 - New Contest! - Submit Your WordPress Theme Designs, Win BIG!
September 1, 2008 - Submit Your Web Site for the Sept 2008 Site of the Month!
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 08, 2008, 12:10:48 AM


Login with username, password and session length


Pages: [1]   Go Down
  Print  
Author Topic: Email header "Content"  (Read 498 times)
NevadaSam
The Queen of Cut & Paste
Galactic Royalty
*****
Offline Offline

Posts: 213



« on: December 10, 2007, 07:17:56 PM »

Sometimes people are receiving emails with a blank text area.
Please show me the proper way to to write the bold part of this line of code.

      $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";


Sam
;
Logged

Today I ask questions... tomorrow I will have answers.
MrPhil
Quantum Encyclopedia Writer
*****
Offline Offline

Posts: 3266



« Reply #1 on: December 11, 2007, 10:22:10 AM »

If you're writing your own HTML email for the PHP mail() function:

    $to = "recipient's address";
    $from_email = "sender's address";
    $subject = "your subject line";
    $header_sep = "\r\n";  // may have to be \n on some systems
   
    // if you embed user-entered text, change CRs to \n's with str_replace()

    $headers  = "MIME-Version: 1.0" . $header_sep ;
    $headers .= "Content-Type: text/html; charset=iso-8859-1" . $header_sep;

    $body  = "<html>\n<head>\n<title>Title For Recipient To See</title>\n";
    $body .= "</head>\n<body>\n";
    $body .= "<p>Here's an email from you</p>\n";
       ...

    $body .= "</body>\n</html>\n";

    if ($from_email != "") {
      $headers = "From: $from_email" . $header_sep . $headers;
      // I think you can put a "Reply-To: ", "Cc: ", etc. in here, too
    }
    $headers .= $header_sep;  // ensure that nothing in the mail body
                              // can add bogus headers
    // make sure resulting body doesn't exceed 70 characters per line
    $body = wordwrap($body,70);

    if (!mail($to, $subject, $body, $headers)) {
      print "<p><font color=\"red\">Unable to send mail! Please try again later.</font></p>\n";
    }


I offer no guarantee that there isn't some way to subvert this with "injection attacks" and generate spam. Usually it's safer to use a well-tested canned mail function, but sometimes you just need your own features.

Non-HTML (plain text) emails are a bit different. I'm not sure how to combine the two (HTML as the primary, plain text as the backup in case the email client can't handle HTML) into one email, but I've heard it can be done.
Logged

NevadaSam
The Queen of Cut & Paste
Galactic Royalty
*****
Offline Offline

Posts: 213



« Reply #2 on: December 14, 2007, 04:53:43 PM »

I believe I have most of it straighten out now. I originally had some extra quotes in the content header. There are still some people telling me that they are getting blank text still. Three of them are have a daltonstate.ga.edu email address so I thinking they may be blocked thought most IT guys will block the whole email. Dalton State College is only 20 miles up the road so I might get may sister to drive me up there next week and talk to the IT guys.

I use $message = "<html><body>".nl2br($message)."</body></html>"; to wrap my text in html.

Logged

Today I ask questions... tomorrow I will have answers.
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM