Solved

i want to send this html as a php email

Posted on 2001-06-11
8
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

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