[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

i want to send this html as a php email

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
owarnes
Asked:
owarnes
1 Solution
 
higijjCommented:
where is the parse error? (which line)?
0
 
us111Commented:
????
0
 
owarnesAuthor Commented:
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!

 
owarnesAuthor Commented:
parse error on line one

is there an easy way to do this?
0
 
owarnesAuthor Commented:
brain ache
0
 
us111Commented:
<?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
 
owarnesAuthor Commented:
I just want to send a bit of code with a php variable in it through email.
0
 
cstsangCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now