Help! Posted July 19, 2006 Share Posted July 19, 2006 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 showthe main reason for this is formatting so It's pretty and easy to read when I get the results of a formthanks Quote Link to comment https://forums.phpfreaks.com/topic/15037-php-in-the-html-generated-by-php/ Share on other sites More sharing options...
trq Posted July 19, 2006 Share Posted July 19, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/15037-php-in-the-html-generated-by-php/#findComment-60465 Share on other sites More sharing options...
Ninjakreborn Posted July 19, 2006 Share Posted July 19, 2006 inserting the variables are the same, if it doesn't work break up the message, end a section with " . variable . "begin message againit 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 quotesnormally 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. Quote Link to comment https://forums.phpfreaks.com/topic/15037-php-in-the-html-generated-by-php/#findComment-60466 Share on other sites More sharing options...
Ninjakreborn Posted July 19, 2006 Share Posted July 19, 2006 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 thissay variable1 is here, and variable 2 is thereit will look like this[quote]HTML E-MailThis is an html emailtry to put php int he html php pageherethen continue your message herethen try to add more heretherethen 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 oneleave 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 Quote Link to comment https://forums.phpfreaks.com/topic/15037-php-in-the-html-generated-by-php/#findComment-60469 Share on other sites More sharing options...
Help! Posted July 19, 2006 Author Share Posted July 19, 2006 thank you this should help a lot :) Quote Link to comment https://forums.phpfreaks.com/topic/15037-php-in-the-html-generated-by-php/#findComment-60470 Share on other sites More sharing options...
Ninjakreborn Posted July 19, 2006 Share Posted July 19, 2006 anytime Quote Link to comment https://forums.phpfreaks.com/topic/15037-php-in-the-html-generated-by-php/#findComment-60471 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.