Solved

i want to send this html as a php email

Posted on 2001-06-11
8
168 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
ID: 6178947
where is the parse error? (which line)?
0
 
LVL 8

Expert Comment

by:us111
ID: 6180196
????
0
 

Author Comment

by:owarnes
ID: 6180246
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:owarnes
ID: 6180255
parse error on line one

is there an easy way to do this?
0
 

Author Comment

by:owarnes
ID: 6180258
brain ache
0
 
LVL 8

Accepted Solution

by:
us111 earned 50 total points
ID: 6180260
<?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
ID: 6180262
I just want to send a bit of code with a php variable in it through email.
0
 
LVL 7

Expert Comment

by:cstsang
ID: 6181304
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

828 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