Jump to content


Photo

php in the html generated by php? :)


  • Please log in to reply
5 replies to this topic

#1 Help!

Help!
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 July 2006 - 01:57 PM

hi

I want to know if it's possible to insert inline php code in an html messege send by a php form e-mail script.  I got the beef of this script online (it's not the final one I'll use I'm just using it to help learn php)
but I want to send an html e-mail but I want to be able to echo variables in the html.  this is what i've tried so far.  also am I doing the POST wrong because that doesn't show in the e-mail either.

<?php
   $to="me@e-mail.com";
   $from=$_POST["email"];
   $subject="My first HTML E-mail";
   $msg=$_POST["message"];
   $message=
   
   '<h1>HTML E-mail</h1>
   <p>This is an <b>HTML</b> e-mail.</p>
   <p>try to put php in the html php page?!?!? <?=$subject?> </p>
   '; 


   $headers = "MIME-Version: 1.0\r\n";
   $headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
   $headers.= "From: $from\r\n";
   if (mail($to, $subject, $message, $headers))
      echo "Message Sent!";
   else
      echo "Failed to send message.";
?>
I got the $subject in the html now becasue the POST won't work (do I need a single quote instead of a double?)  but I eventually want to send what people write in a comment box.

the html works but the php in the html doesn't show

the main reason for this is formatting so It's pretty and easy to read when I get the results of a form
thanks

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 19 July 2006 - 02:01 PM

php runs on the server, not the client, where do you expect this php to be parsed?

You need to turn you php variables into html output on the server before you send it to the client.

#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 19 July 2006 - 02:03 PM

inserting the variables are the same, if it doesn't work break up the message, end a section with " . variable . "begin message again
it will add them in there, in the proper places, it wouldn't be that hard you should be able to substitute them like this anyway
{$variable}
or if it's post or get you do the same thing, but when you are enterpolating those you leave off the single quotes
normally its
$_POST['variable']
$_GET['variable']
when you are interpolating it's
$POST[variable]
$_GET[variable]
Be careful of html mail, because php always sends the mail 2 times, atleast what php.net says, it ALWAYS sends 2 emails so if it's a mailing list, they get 2 emails.  

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 19 July 2006 - 02:08 PM

Also you can ONLY interpolate with double quotes, here is an example

$message = "
   <h1>HTML E-mail</h1>
   <p>This is an <b>HTML</b> e-mail.</p>
   <p>try to put php in the html php page" . $variable1 . "</p>
   <p>Then you continue your message here</p>  
   <p>Then you try to add more here" . $variable2 . "</p>
   <p>Then you continue down here even more</p>";

  Also keep in mind this will look retarded, atleast in the email it will be like this
say variable1 is here, and variable 2 is there
it will look like this

HTML E-Mail
This is an html email
try to put php int he html php pagehere
then continue your message here
then try to add more herethere
then you continue down here even more

You see how they run together, the way to fix this, one way is that hte end of each one
leave a blank line like this

$message = "
   <h1>HTML E-mail</h1>
   <p>This is an <b>HTML</b> e-mail.</p>
   <p>try to put php in the html php page " . $variable1 . "</p>
   <p>Then you continue your message here</p>  
   <p>Then you try to add more here " . $variable2 . "</p>
   <p>Then you continue down here even more</p>";
That should fix your problem, if you are sending more than 20-30 emails at once, drop the html email with php, and use the pear package, it opens up a constant stream unstead of killing server power by opening up 20-2000 streams, one for each email.  You can check that at php.net  just search pear

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#5 Help!

Help!
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 July 2006 - 02:11 PM

thank you

this should help a lot

:)

#6 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 19 July 2006 - 02:14 PM

anytime

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users