Page 1 of 3 123 LastLast
Results 1 to 15 of 37
  1. #1
    Join Date
    May 2005
    Location
    Gaza, Palestine
    Posts
    25

    Arrow php: simple code to send HTML email

    good day,

    this simple code lines will help you sending html email.
    of course you can enhance for your need eg. using form, using it in newsletter etc.
    but outcoming emails might reported as spam ... so when you test don't forget to check you bulk/junk mail lol..


    PHP Code:
    <?
        
    //change this to your email.
        
    $to "m@maaking.com";
        
    $from "m2@maaking.com";
        
    $subject "Hello! This is HTML email";

        
    //begin of HTML message
        
    $message = <<<EOF
    <html>
      <body bgcolor="#DCEEFC">
        <center>
            <b>Looool!!! I am reciving HTML email......</b> <br>
            <font color="red">Thanks Mohammed!</font> <br>
            <a href="http://www.maaking.com/">* maaking.com</a>
        </center>
          <br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
      </body>
    </html>
    EOF;
       
    //end of message
        
    $headers  "From: $from\r\n";
        
    $headers .= "Content-type: text/html\r\n";

        
    //options to send to cc+bcc
        //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
        //$headers .= "Bcc: [email]email@maaking.cXom[/email]";
        
        // now lets send the email.
        
    mail($to$subject$message$headers);

        echo 
    "Message has been sent....!";
    ?>
    the easy can be hard.
    Mohammed Ahmed - ME. Palestine
    http://www.maaking.com
    Email/MSN: m@maaking.com

  2. Thread Summary This thread contains 2 different methods of code to send HTML email.

    The first simple php script is included in the first post.
    PHP Code:
    <?
        
    //change this to your email.
        
    $to "m@maaking.com";
        
    $from "m2@maaking.com";
        
    $subject "Hello! This is HTML email";

        
    //begin of HTML message
        
    $message = <<<EOF
    <html>
      <body bgcolor="#DCEEFC">
        <center>
            <b>Looool!!! I am reciving HTML email......</b> <br>
            <font color="red">Thanks Mohammed!</font> <br>
            <a href="http://www.maaking.com/">* maaking.com</a>
        </center>
          <br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
      </body>
    </html>
    EOF;
       
    //end of message
        
    $headers  "From: $from\r\n";
        
    $headers .= "Content-type: text/html\r\n";

        
    //options to send to cc+bcc
        //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
        //$headers .= "Bcc: [email]email@maaking.cXom[/email]";
        
        // now lets send the email.
        
    mail($to$subject$message$headers);

        echo 
    "Message has been sent....!";
    ?>
    The second code uses MIME
    PHP Code:
    <?
        
    //change this to your email.
        
    $to "m@maaking.com";
        
    $from "m2@maaking.com";
        
    $subject "Hello! This is HTML email";

        
    //begin of HTML message
        
    $message "<html>
      <body bgcolor=\"#DCEEFC\">
        <center>
            <b>Looool!!! I am reciving HTML email......</b> <br>
            <font color=\"red\">Thanks Mohammed!</font> <br>
            <a href=\"http://www.maaking.com/\">* maaking.com</a>
        </center>
          <br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
      </body>
    </html>"
    ;
       
    //end of message

        // To send the HTML mail we need to set the Content-type header.
        
    $headers "MIME-Version: 1.0rn";
        
    $headers .= "Content-type: text/html; charset=iso-8859-1rn";
        
    $headers  .= "From: $from\r\n";
        
    //options to send to cc+bcc
        //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
        //$headers .= "Bcc: [email]email@maaking.cXom[/email]";
        
        // now lets send the email.
        
    mail($to$subject$message$headers);

        echo 
    "Message has been sent....!";
    ?>
    For either code, simply update the details to what you need. EXAMPLE: me @ MY domain dot com

    Contributors: SoftWareRevue

  3. #2
    Join Date
    May 2005
    Location
    Gaza, Palestine
    Posts
    25
    this one uses MIME.

    PHP Code:
    <?
        
    //change this to your email.
        
    $to "m@maaking.com";
        
    $from "m2@maaking.com";
        
    $subject "Hello! This is HTML email";

        
    //begin of HTML message
        
    $message "<html>
      <body bgcolor=\"#DCEEFC\">
        <center>
            <b>Looool!!! I am reciving HTML email......</b> <br>
            <font color=\"red\">Thanks Mohammed!</font> <br>
            <a href=\"http://www.maaking.com/\">* maaking.com</a>
        </center>
          <br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
      </body>
    </html>"
    ;
       
    //end of message

        // To send the HTML mail we need to set the Content-type header.
        
    $headers "MIME-Version: 1.0rn";
        
    $headers .= "Content-type: text/html; charset=iso-8859-1rn";
        
    $headers  .= "From: $from\r\n";
        
    //options to send to cc+bcc
        //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
        //$headers .= "Bcc: [email]email@maaking.cXom[/email]";
        
        // now lets send the email.
        
    mail($to$subject$message$headers);

        echo 
    "Message has been sent....!";
    ?>
    the easy can be hard.
    Mohammed Ahmed - ME. Palestine
    http://www.maaking.com
    Email/MSN: m@maaking.com

  4. #3
    Join Date
    Apr 2002
    Location
    New Jersey
    Posts
    354
    If you are looking for a great php mailer class I would recommend http://phpmailer.sourceforge.net.

    I have been using this class for 3 years and love it. It has tons of features, redundant smtp servers, smtp auth, word wrap, multiple tos, ccs, etc.

    This class is also works really weel with attachments. I use it to send spreadsheet bandwidth reports based on sql queries.
    Solar VPS The Best Price to Performance Ratio In Cloud and VPS Hosting
    e: sales@solarvps.com
    The SolarSystem - On Demand VM Creation, DNS Control and more.
    Speed Test: speed.fortressitx.com

  5. #4
    Join Date
    Jul 2005
    Location
    Minnesota, USA
    Posts
    6
    Originally posted by Aaton35
    If you are looking for a great php mailer class I would recommend http://phpmailer.sourceforge.net.

    I have been using this class for 3 years and love it. It has tons of features, redundant smtp servers, smtp auth, word wrap, multiple tos, ccs, etc.

    This class is also works really weel with attachments. I use it to send spreadsheet bandwidth reports based on sql queries.
    Thanks for that link! I checked it out and it looks like I can definitely find a use for this. Thanks again!

  6. #5
    phpclasses.net is a great resource for all this kind of stuff

    hth

    craig

  7. #6
    Join Date
    Sep 2004
    Location
    England UK
    Posts
    121
    for more information on php's mail() function you can visit: php sendmail tutorial
    Read Tabloids - Warning Experimental.

  8. #7
    take a look at PEAR project functionalities - it has everything, that someone can struggle for....

  9. #8
    Great Mohammed

    but if i need this email send it to me at specific time ??? what is the change
    can i make to do that ?

    thanxs

  10. #9

    Sending PHP in the HTML sent via PHP :)

    Hey thanks for anyhelp offered.

    I am hoping to use this code at the start of this thread to send HTML to users. The email send the HTML but if I do an:

    <? echo "$Vars"; ?> in the code the php does not show up?

    Is there a way to get dynamic data sent in the HTML via PHP?

    thanks so much for your help.

    -Ed

  11. #10
    Join Date
    Nov 2005
    Posts
    268
    yes ed
    In Heredoc or regular strings using $varname or {$varname} will give you the dynamic output you want.

    PHP Code:
    //Any of these methods will allow inserting of variable values into the variable
    $drink "Coke";
    $se "her";
    $heredoc <<< EMAIL
    The Customer would like a straw in $se $drink.
    EMAIL;
    $stringdblquote "The Customer would like a straw in $se $drink.";
    $concatnate 'The Customer would like a straw in ' $se ' ' $drink;
    //unfortunatly without using {} php becomes greedy. 
    $invalid "The Customers would like a straw in their $drinks."//outputs "The Customers would like a straw in their ."
    //using {} can force php to evalueate the correct number of letters.
    $valid "The Customers would like a straw in their {$drink}s."//outputs "The Customers would like a straw in their Cokes." 

  12. #11

    A thousand thanks to Korvan

    hey Thanks so much Korvan for the advice I was looking for. It really helped me out. I am pretty pumped about sending dynamic data in emails in HTML and php.


    thanks!


    HUE THEM ANN!



    -Ed

  13. #12

    One More Question

    Hey Korvan,

    Another question for you. How do I use a for in this html? You will see my example below. Basically I am calling the VARS from a datadase and creating html tables base on the number of results. Then I want to email those VARS in an html format. Any suggestions?

    I tried useing $HTML_Data = 'include'DatabaseScript.php'; and then putting $HTML_VAR in the code below in place of the For Loop, but that didn't work either.

    thanks for your time. If you have a paypal account I would like to donate something to you to say thanks for your time. Have a great night.


    //Any of these methods will allow inserting of variable values into the variable
    $drink = "Coke";
    $se = "her";
    $heredoc <<< EMAIL

    <? $TheCount++; for($i=1; $i < $TheCount; $i++) { $HailMary .=$ItemsOrdered[$i][0];$HailMary .=$ItemsOrdered[$i][1];$HailMary .=$ItemsOrdered[$i][2]; $HailMary .=$ItemsOrdered[$i][3]; $HailMary .=$ItemsOrdered[$i][4]; }//$HailMary .= "<br>"; echo "$HailMary"; ?>

    EMAIL;
    $stringdblquote = "The Customer would like a straw in $se $drink.";

  14. #13

    working... kind of.

    Ok so I got an include to work with spiting out the html, however it is not getting my Vars from the Database? Any Suggestions? Here is the code:

    $MyVars = get_include_contents('MyFile.php');
    function get_include_contents($filename) {
    if (is_file($filename)) {
    import_request_variables ( 'gp' );
    ob_start();
    include $filename;
    $contents = ob_get_contents();
    ob_end_clean();
    return $contents;
    }
    return false;
    }



    //begin of HTML message
    $message = <<<EOF

    $MyVars
    EOF;

  15. #14
    Join Date
    Nov 2005
    Posts
    268
    I do not know how to fix that unless i know whats query you are running.

    So what is your sql query? I could give you an example

    Also you cannot put <? ... ?> inside the heredoc and expect php to process that code. It just wont, instead it will output those tags. (or dump them in a var).
    PHP Code:
    //you only can run database query after the connection to your database is open.
    $sql "SELECT id, name, job FROM example_tbl";
    if(!(
    $result mysql_query($sql)))
    {
     
    //error
    }
    else
    {
      
    //grab data from the database

      
    $output NULL;
      
    //create our welcome or header message
      
    $output .= "Hello Dude, this is an example email!<br />\r\n";
      while((
    $arr mysql_fetch_assoc($result)))
      {
       
    $output .= "Person <b>{$arr['name']}</b> does {$arr['job']}<br />\r\n";
      }
     
    //close the output
     
    $output .= "<br />\r\n<br />\r\nHave a nice day!<br />\r\n Mr. Ed";

    }
    //output now contains what you are emailing. note this is just an example and 
    //you will need to adjust it to fit your needs. 

  16. #15

    Post 4

    See example below:

Page 1 of 3 123 LastLast

Related Posts from theWHIR.com

Posting Permissions

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