Solved

i want to send this html as a php email

Posted on 2001-06-11
8
164 Views
Last Modified: 2008-02-07
I have this html code which echo variable name in a table
and I want to send using php on a form submit. The variable $body will contain the html code and the echhhoed result $name.

can anyone show me how to do it I keep getting parse errors with what i'm doing.

//the code to be sent in the email

<table width="300" border="0" cellpadding="2">
            <tr valign="top">
              <td colspan="2">
                <p><b>test form one</b></p>
              </td>
            </tr>
            <tr valign="top">
              <td width="109">&nbsp;</td>
              <td width="177">this is test form one</td>
            </tr>
            <tr valign="top">
              <td width="109">
                <p><b>NAME</b></p>
              </td>
              <td width="177">
                <?php echo $name; ?>
              </td>
            </tr>
</table>
0
Comment
Question by:owarnes
8 Comments
 
LVL 2

Expert Comment

by:higijj
Comment Utility
where is the parse error? (which line)?
0
 
LVL 8

Expert Comment

by:us111
Comment Utility
????
0
 

Author Comment

by:owarnes
Comment Utility
will this work, do you understand?

<?php $body = "<table width="300" border="0" cellpadding="2">
           <tr valign="top">
             <td colspan="2">
               <p><b>test form one</b></p>
             </td>
           </tr>
           <tr valign="top">
             <td width="109">&nbsp;</td>
             <td width="177">this is test form one</td>
           </tr>
           <tr valign="top">
             <td width="109">
               <p><b>NAME</b></p>
             </td>
             <td width="177">
               <?php echo $name; ?>
             </td>
           </tr>
</table>" ; ?>

Then send that to a form which emails it.
<?php mail($to,$subject,$body) ; ?>
0
 

Author Comment

by:owarnes
Comment Utility
parse error on line one

is there an easy way to do this?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:owarnes
Comment Utility
brain ache
0
 
LVL 8

Accepted Solution

by:
us111 earned 50 total points
Comment Utility
<?php $body = '<table width="300" border="0" cellpadding="2">
                               <tr valign="top">
                                 <td colspan="2">
                                   <p><b>test form one</b></p>
                                 </td>
                               </tr>
                               <tr valign="top">
                                 <td width="109">&nbsp;</td>
                                 <td width="177">this is test form one</td>
                               </tr>
                               <tr valign="top">
                                 <td width="109">
                                   <p><b>NAME</b></p>
                                 </td>
                                 <td width="177">
                                   $name
                                 </td>
                               </tr>
                     </table>' ; ?>
0
 

Author Comment

by:owarnes
Comment Utility
I just want to send a bit of code with a php variable in it through email.
0
 
LVL 7

Expert Comment

by:cstsang
Comment Utility
Try this one
<?
/*

 *  Class mime_mail

 *  Original implementation by Sascha Schumann <sascha@schumann.cx>

 *  Modified by Tobias Ratschiller <tobias@dnet.it>:

 *      - General code clean-up

 *      - separate body- and from-property

 *      - killed some mostly un-necessary stuff

 */

 

class mime_mail

 {

       var $parts;

       var $to;

       var $from;

       var $headers;

       var $subject;

       var $html_body=0;

        /*

        *     void mime_mail()

        *     class constructor

        */        

       function mime_mail()

        {

            $this->parts = array();

            $this->to =  "";

            $this->from =  "";

            $this->subject =  "";

            $this->body =  "";

            $this->headers =  "";

        }

      

        /*

        *     void add_attachment(string message, [string name], [string ctype])

        *     Add an attachment to the mail object

        */

       function add_attachment($message, $name =  "", $ctype =  "application/octet-stream")

        {

         $this->parts[] = array (

                                 "ctype" => $ctype,

                                 "message" => $message,

                                 "encode" => $encode,

                                 "name" => $name

                                );

        }

      

      /*

       *      void build_message(array part=

       *      Build message parts of an multipart mail

       */

      function build_message($part)

       {

             $message = $part[ "message"];

             $message = chunk_split(base64_encode($message));

             $encoding =  "base64";

             return  "Content-Type: ".$part[ "ctype"].

                                    ($part[ "name"]? "; name = \"".$part[ "name"]. "\"" :  "").

                                     "\nContent-Transfer-Encoding: $encoding\n\n$message\n";

       }

      

      /*

       *      void build_multipart()

       *      Build a multipart mail

       */

      function build_multipart()

       {

            $boundary =  "b".md5(uniqid(time()));

            $multipart =  "Content-Type: multipart/mixed; boundary = $boundary\n\nThis is a MIME encoded message.\n\n--$boundary";

            

            for($i = sizeof($this->parts)-1; $i >= 0; $i--)

            {

            $multipart .=  "\n".$this->build_message($this->parts[$i]). "--$boundary";

            }

            return $multipart.=  "--\n";

       }

      

      /*

       *      void send()

       *      Send the mail (last class-function to be called)

       */

      function send()

       {

            $mime =  "";

            if (!empty($this->from))

            $mime .=  "From: ".$this->from. "\n";

            if (!empty($this->headers))

            $mime .= $this->headers. "\n";

            if (!empty($this->body))

            {if ($this->html_body!=1)

            $this->add_attachment($this->body,  "","text/plain");  

            else

            $this->add_attachment($this->body,  "","text/html");    

            }

            $mime .=  "MIME-Version: 1.0\n".$this->build_multipart();

            $r=@mail($this->to, $this->subject,  "", $mime) or die("Sorry!Sending failure") ;

            return $r;

       }

};  // end of class

//---------------------------------------------------------------------------------

 if (empty($HTTP_POST_VARS))

    {?>


      <form method="POST">

      <table><tr><td align="RIGHT">

      Name?F<input type="Text" name="from"><br>

      Sender Email Address?F<input type="Text" name="email"><br>

      Receiver Email Address:<input type="Text" name="to"><br>

      Title?F<input type="Text" name="subject" value="Email Testing..."><br>

      Mail content?F

      <textarea name="msg" cols="20" rows="5" wrap="VIRTUAL">Email Testing<hr>

      </textarea><br>

      <input type="Submit" name="submit" value="Send">

      </td></tr></table>

      </form>

<? }

 else

   {

       $attachment = fread(fopen("poweredby.png", "r"), filesize("poweredby.png"));

       $mail = new mime_mail();

       $mail->from = $from;

       //$mail->headers = "Errors-To: foo@bar.com";

      

       $mail->to = $to;

       $mail->subject = $subject;

       $mail->body = $msg;

       $mail->add_attachment("$attachment", "poweredby.png", "image/png");

       $mail->html_body=1;   //send html format email

       //$mail->add_attachment("$attachment", "poweredby.png", "image/png");

       //echo $mail->send();

       $mail->send();

   }

?>

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now