Solved

i want to send this html as a php email

Posted on 2001-06-11
8
171 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
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!

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to implement server side field validation and display customized error messages to the client.
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

688 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