SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is it possible to send an html email with php and mysql data?

    I'm trying to send a form that has both html, php, and mysql queries is this possible? Any documentation?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Are you saying someone is typing code into the form and you want that code to appear in the e-mail? There wouldn't be any special handling for that, it's just text like other user input.

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, I'm saying I want stuff to be pulled from the database and sent statically.

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    mysql_connect("host""user""pass");
    mysql_select_db("dbname");

    $sql "SELECT name, email FROM user_table";
    $sql_result mysql_query($sql);
    while (
    $row mysql_fetch_array($sql_result)) {
      
      
    $body "Dear " $row['name'] . ", \n\n";
      
    $body .= "Thank you for being a user of our service!\n\n";
      
    $body .= "Sincerely,\n";
      
    $body .= "Dan";

      
    mail($row['email'], "Just a Thank You!"$body"From: admin@example.com");



  5. #5
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the above how does it know address to send it to and things?

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    they are taken from the database and assigned $row['email'], assuming you have their email address in the database.....
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well i do have, but I need it to email like 4 or 5 different accounts.

  8. #8
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also I need to use html to make a table to put the data in?

  9. #9
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Have a read through http://uk.php.net/manual/en/function.mail.php, it should answer all your questions
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  10. #10
    SitePoint Zealot Servyces's Avatar
    Join Date
    Jun 2007
    Location
    The Netherlands
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically you can build a complete php/mysql driven page and mail the contents once everything is parsed. Just put all the commands within the $body variable.

    The below example would mail the results that phpinfo returns to the given e-mail address.

    PHP Code:
    <?php
    $body 
    phpinfo();
    mail('you@yourdomain.com','PHP Info from server',$body);
    ?>
    You get the idea. You can do this with both PHP and HTML code and have it sent once everything is parsed.
    Last edited by Servyces; Jun 13, 2007 at 10:29.
    Servyces.com
    Where itís all about you.
    Your partner in online solutions.
    Visit our website at http://www.servyces.com/

  11. #11
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean put all the commands within the body variable?

  12. #12
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Servyces View Post
    Basically you can build a complete php/mysql driven page and mail the contents once everything is parsed. Just put all the commands within the $body variable.

    The below example would mail the results that phpinfo returns to the given e-mail address.

    PHP Code:
    <?php
    $body 
    phpinfo();
    mail('you@yourdomain.com','PHP Info from server',$body);
    ?>
    You get the idea. You can do this with both PHP and HTML code and have it sent once everything is parsed.
    Off Topic:

    That wouldn't work since phpinfo() doesn't return a string but instead outputs directly.

  13. #13
    SitePoint Zealot Servyces's Avatar
    Join Date
    Jun 2007
    Location
    The Netherlands
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wickedneat View Post
    What do you mean put all the commands within the body variable?
    To put all the PHP code you would like executed within the body variable of the e-mail.
    Last edited by Servyces; Jun 13, 2007 at 10:29.
    Servyces.com
    Where itís all about you.
    Your partner in online solutions.
    Visit our website at http://www.servyces.com/

  14. #14
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So everything I want to email has to be in there?

  15. #15
    SitePoint Zealot Servyces's Avatar
    Join Date
    Jun 2007
    Location
    The Netherlands
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes or references to earlier executed code. Like:

    PHP Code:
    $query mysql_query("SELECT name FROM customers WHERE id=3");
    while (
    $row mysql_fetch_assoc($query)) {
        
    $name $row['name'];
    }

    $body "Dear $name, \r\n";
    $body .= "\r\n";
    $body .= "Thank you for your inquiry. We will get back to you as soon as possible.";

    mail ('me@myinbox.com','Inquiry',$body); 
    Last edited by Servyces; Jun 13, 2007 at 10:27.
    Servyces.com
    Where itís all about you.
    Your partner in online solutions.
    Visit our website at http://www.servyces.com/


Bookmarks

Posting Permissions

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