Jump to content

php in the html generated by php? :)


Help!

Recommended Posts

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.

[code]<?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.";
?>[/code]
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
Link to comment
Share on other sites

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.  
Link to comment
Share on other sites

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

[code]$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>";[/code]

  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
[quote]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[/quote]
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

[code]$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>";[/code]
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.