Cron Job > Content in HTML format

Discussion in 'PHP' started by JRJR, Aug 15, 2006.

  1. #1
    Hi everybody!

    I have a php script that prints some things. That script is executed by a cron job: php /home/xpto/public_html/stats_script.php and its content is being sent to a specified e-mail address.

    The problem is that the written content doesn't come in HTML format. For instance, I'm printing HTML table (<table><tr><td>...) but the e-mail shows the HTML tags and not the formatted table.

    I would appreciate any help on this.

    Thanks!
     
    JRJR, Aug 15, 2006 IP
  2. DrMalloc

    DrMalloc Peon

    Messages:
    130
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm not entirely sure about having the email sent as HTML, but I thought I'd share an interesting function of the 'lynx' browser included with most linux distributions. By running lynx with the -dump option, and a url parameter, you can dump the output of a page as it would look in a text browser (which parses the tables and so forth). So for example:

    lynx -dump http://www.google.com/

    The output of which is:
    
                         [1]Personalized Home | [2]Sign in
    
                                       Google
    
       Web    [3]Images    [4]Video^New!    [5]News    [6]Maps    [7]more »
       [8]Books
       [9]Froogle
       [10]Groups
       [11]even more »
       [12][x2.gif]
    
         _______________________________________________________
       Google Search I'm Feeling Lucky   [13]Advanced Search
         [14]Preferences
         [15]Language Tools
    
        [16]Advertising Programs - [17]Business Solutions - [18]About Google
    
                                    ©2006 Google
    
    Code (markup):
    (and a key for which number points to which page).
     
    DrMalloc, Aug 15, 2006 IP
  3. JRJR

    JRJR Active Member

    Messages:
    172
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    I appreciate that funcionality but I urgently need a solution to my question. :(

    Anyone knows?
     
    JRJR, Aug 15, 2006 IP
  4. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I would guess that the emailer is not setting the correct content type on the email. If you want an email to be displayed as HTML, you need to tell the mail client through a header. If you were sending via the PHP mail function, you would need something like:

    mail($to, $subject, $message, "From: $from\nContent-Type: text/html; charset=iso-8859-1");

    if that makes sense.

    So that's basically the problem: the cron emailer isn't sending an HTML content-type header with the email.

    Can you change that? I don't know.
     
    TwistMyArm, Aug 15, 2006 IP
  5. JRJR

    JRJR Active Member

    Messages:
    172
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    No. The only things I can do is: define a e-mail address where the cron job output will be sent; the moments when the cron job will be run and the command itself.
     
    JRJR, Aug 15, 2006 IP
  6. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yeah... I guess the only other thing you could do is change your script a bit: add a 'flag' so that it knows to store the output in a string instead of outputting it and then email the string using the right content headers.

    When you call the script from cron, just be sure to set that flag.

    I know it's a bit of a pain, but that's all I can see as the options: essentially having the script email the output itself, as opposed to having cron email it.

    Hopefully that makes sense!
     
    TwistMyArm, Aug 15, 2006 IP
  7. Smyrl

    Smyrl Tomato Republic Staff

    Messages:
    13,740
    Likes Received:
    1,702
    Best Answers:
    78
    Trophy Points:
    510
    #7
    Do you really want to send out e-mail in html format when some recipients e-mail programs do not handle html?
     
    Smyrl, Aug 15, 2006 IP
  8. JRJR

    JRJR Active Member

    Messages:
    172
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #8
    Thanks TwistMyArm.

    Actually I would love to create fancy reports with tables and other html stuff.
    Probably, the easiest way is to organize the content only as text...with spaces, pipes, etc...

    If anyone else have a different idea, post here. Thanks in advance! :D
     
    JRJR, Aug 15, 2006 IP