A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: Format text in email from PHP ??

  1. #1
    Senior Member Cadence's Avatar
    Join Date
    Aug 2000
    Location
    Columbus, Ohio
    Posts
    3,428
    Hello ..

    Is it possible (PHP-newbie) to format the text that is sent through email (via a PHP script) ??

    Such as this code :

    Code:
    $EmailBody = "Sent By: $Name\nEmail Address: $Email\nComments:\n$Comments\n\n"
    I would like the "Sent By:" text (as well as other areas) to be in Bold text in the email I receive (from a contact form) ... I tried using all the usual formatting styles, but none seem to work ... I assume either I'm missing something vital in the code -- or it's simply not possible ...


    Thanks in advance

    Peaces,
    Cadence
    [Edited by Cadence on 05-15-2002 at 04:14 PM]

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    I too would like to know this..as I am just starting PHP as well....I am trying (my damnedest) to write my own PHP mail script...(to no avail) but when I do get it..I would like to know how to format it...so the end result is little more organized...and presentable..

    -whispers-

  3. #3
    Senior Member
    Join Date
    Jun 2000
    Posts
    687
    You can use HTML, but you have to set the content type so the mail program that's recieving the email knows that it will be HTML.

    So something like this:

    < ?php

    $ToName = "Me";
    $ToEmail = "Me@here.com";
    $FromName = "You";
    $FromEmail = "You@here.com";
    $Subject = "This is HTML Email";

    $Message = $ToName." <br><br><img src=\"http://www.SomeImageToDisplay.com/image.gif\" align=\"left\">You have been sent an email from ".$FromName."<br><br><b>This is Bold Text</b><br><i>This is Italic Text in your email<br><br>This is html Email<br>";

    $headers = "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "From: ".$FromName." <".$FromEmail.">";

    mail($ToEmail, $Subject, $Message, $headers);

    print "Your mail has been sent";
    ?>

    They have more on this on the PHP Docs page for Mail();

    http://www.php.net/manual/en/function.mail.php

    It sometimes differs a bit if your using NT vs. Anything else.

  4. #4
    Senior Member Cadence's Avatar
    Join Date
    Aug 2000
    Location
    Columbus, Ohio
    Posts
    3,428
    Thanks Snow ... I'll give it a try ...

    -Cadence

  5. #5
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    Hey all...I have loked at your code....and being NEW to PHP (completely) I am having trouble seeing exactly what is added so your PHP e-mali will be sent using basic HTML commands.

    My e-mail code doesnt look like the one you posted...and so I really dont know what parts need to be added?...

    Are the only part that needs to be added:

    1. the two $header lines??
    2. The actual HTML tags that you want to add?

    Is this it?..I wil lpost my PHP mail script ...I DO NOT WANT TO CHANGE THIS SCRIPT IN ANY WAY.. so if could just show me what lines need to be added (and why) I would appcreciate it....maybe color code it if it is possible on this forum!

    Thanks

    -whispers-
    Code:
    <?php
    $Subject = "Form Inquiry"; 
    $MailTo = "whispers007@hotmail.com"; 
    $Body = "From: $name\nE-mail: $MailFrom\n\nQuestions/Comments: $message\n"; 
    $From = "From: DMStudios_Form_Reply <$MailFrom>";
     
    mail($MailTo, "$Subject", "$Body", "$From"); 
    ?>
    Just put the lines of code that should added...again..I want to leave my code alone for now! Thanks
    lol..and as I speak..Cadence has responded...lol (e-mail notification)
    [Edited by whispers on 05-17-2002 at 02:18 AM]

  6. #6
    Senior Member Cadence's Avatar
    Join Date
    Aug 2000
    Location
    Columbus, Ohio
    Posts
    3,428
    The script I used, is in fact from Snowdude ... at http://www.flash-db.com ... A direct link to his tutorial here at Flashkit is :
    http://www.flashkit.com/tutorials/Dy...58/index.shtml

    There are a few tutorials ... The Email in Flash tutorial will explain exactly what you need to modify in the PHP code (and why) ...

    Peaces,
    Cadence

    and thanks again Snow

  7. #7
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    Thanks...the second link...didnt have anything about adding HTML in your PHP script mail..did it?..I might have missed it?..was it in the PHP script section??

    I will check on the first link now..thanks

    UPDATE: I went to first link.. (I keep heariong about this site...but I cant find ANYTHING there...to busy for me) can you tell me what you got from that site? and where?

    If you can see my script above..what lines are to be added to that as it is already?..or does the script need to be altered? (I mean what is already there)



    -whispers-

  8. #8
    Senior Member
    Join Date
    Jun 2000
    Posts
    687
    No their was nothing about HTML email in that link.

    The part that was added in this post was:

    $headers = "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "From: ".$FromName." <".$FromEmail.">";

    mail($ToEmail, $Subject, $Message, $headers);


    you need to add the headers part to tell the recieving email client to expect HTML instead of just text.

  9. #9
    they call me the_jump... le_saut's Avatar
    Join Date
    Mar 2001
    Posts
    536
    Whispers:

    Remember in the last thread I showed how the From: CC: and BCC headers all go in the 4th parameter of mail().

    eg
    mail(to, subject, body, optional headers, optional additional headers)

    You can add the Content-type to this 4th parameter.
    eg
    Code:
    $From = "From: DMStudios_Form_Reply <$MailFrom>";
    $BCC = "BCC: blindCarbon@somedomain.com";
    $CC = "CC: carbon@anotherdomain.com.au";
    //then also
    $Mime = "MIME-Version: 1.0";
    $HTML = "Content-type: text/html; charset=iso-8859-1";
    //mail it
    mail($to, $subject, $body, $From\n$BCC\n$CC\n$Mime\n$HTML)
    Mime tells the client what type of data to expect (Standard MIME).

    It's easy to do, but it dredges up the issue of compatibility. Can the email client your are a sending to render HTML properly? and even if it can has the user turned it off.

    The answer is to send two versions (text and html) of the same message, splitting the message with a boundary that the client recognises.

    You can see this happening at this link : http://www.webmasterbase.com/article/679/50

    Remember not to make those HTML emails to large. Email clients aren't browsers.
    I have Eudora set to ignore everything >5kb.


    Cheers

    james




  10. #10
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    So would my code be this?

    <?php
    $Subject = "Form Inquiry";
    $MailTo = "whispers007@hotmail.com";
    $Body = "From: $name\nE-mail: $MailFrom\n\nQuestions/Comments: $message\n";
    $headers = "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers = "From: DMStudios_Form_Reply <$MailFrom>";


    mail($MailTo, "$Subject", "$Body", "$headers");
    ?>

    or would this be incorrect?...Thanks....

  11. #11
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    la_saut:...I didnt even see your post before I posted...I will look at what you posted..thanks...I looked at it briefly..I think I sorta get it..let me try to change my code..using what you have explained..and let me post it to see if it is ok?....ok?

    And as for the HTML mail thing..they are only getting sent to me...I just want to practice thats all. I will look into the send two e-mail types as you said. That will be my 3rd and final installment on teaching myself how to write a mail script in PHP. (My first lesson...) Am happy now!...or soon will be!

    Post to you all soon!

    -whispers-

  12. #12
    Senior Member
    Join Date
    Jun 2000
    Posts
    687
    Not Quite,

    Le_saut's explaination was better then what I mentioned although both will work - his a bit better.

    Anyways I think this may be getting a little confusing - I'm starting to get confused myself ha ha. Things are getting mixed and matched..

    This might be closer - although will probably only work with Outlook or HTML email viewers like Netscape, aol, and hotmail.

    <?php
    $Subject = "Form Inquiry";
    $MailTo = "whispers007@hotmail.com";

    $Body = "From: $name<br>E-mail: $MailFrom<br><br>Questions/Comments: $message<br><hr><i>This is Italic Text</i><br><br>This is bold text</b>";

    $headers = "Content-type: text/html; charset=iso-8859-1";
    $headers .= "From: DMStudios_Form_Reply";


    mail($MailTo, "$Subject", "$Body", "$headers");
    ?>

    I'm not 100% on this - I never really now till I start testing it out with lots of different email clients. Anyways anything in the $Body part - can use HTML tags such as <b> for bold, <i> for italic, <img> <table> <hr> ect. Anything you can write in html you can write in the email.

    You can even Embed SWF's with this. Just copy and paste the Object/embed html code and use that in the Body tag. Be sure to comment out \" the double quotes though.

    That only works (SWF's in email) on 1 or 2 email clients though. Embedding SWF's will not work if the User has a Hotmail, Netscape, AOL, account and quite a few others.

  13. #13
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    What did I miss on my version of it???

    I dont see any difference except that you actually added in the HTML tags for me....oh I see I had bad sytax as well...thank you. I just tried it..it works fine...but how do I make the e-mail the user enters...be a link in the body window..am testing it now....but I dont think I have it right....or my mail server could be slow....which is probably the case..since they stink!..lol

    -whispers-

  14. #14
    Senior Member
    Join Date
    Jun 2000
    Posts
    687
    In yours you where missing the:


    .=


    dot equals sign in the headers part. The dot operator will join together the two strings into one. Otherwise it will exclude the first string in the variable header.


    Yours:

    $headers = "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers = "From: DMStudios_Form_Reply <$MailFrom>";


    Mine:

    $headers = "Content-type: text/html; charset=iso-8859-1";
    $headers .= "From: DMStudios_Form_Reply";


    I think you will need the \r\n in the first line of yours however. The \r\n specify's a line break which is needed between headers.


  15. #15
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    yes..I saw that at the last minute....question:

    I added the bold options...around the FROM: and E-MAIL: parts..and it works fines...I tried to change the fontcolor and no go. I also tried to make it so the when I get the email.....
    in the BODY when it has the users e-mail displayed (from the variable) I want this to be displayed as a link...like it was before...I tried using anchor tags..but again..no go...any tips?..

    Thanks...I am still messing with it.

    -whispers-

  16. #16
    they call me the_jump... le_saut's Avatar
    Join Date
    Mar 2001
    Posts
    536
    Thanks...I am still messing with it.
    -whispers- [/B]
    Messing with mail() is the best way to work it out, see what happens on various clients and webmail platforms. (Hotmail is interesting)

    experiment and ye shall find.

    James

  17. #17
    Senior Member
    Join Date
    Aug 2000
    Location
    Seoul, South Korea
    Posts
    1,310
    Hi all,
    I have posted this link before to a couple of you guys but for those that haven't i found this most helpful.

    http://www.webmasterbase.com/article.php?pid=24&aid=679


  18. #18
    they call me the_jump... le_saut's Avatar
    Join Date
    Mar 2001
    Posts
    536

    html email help

    URL's

    There's also a good tute at zend.com - also with some good tips on user privacy and not abusing a user's email client.

    and here at PHP builder (tho' slightly more technical).


    HTH

    James

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center