473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Help inserting php code in html in $message

Greetings,
I have not been able to find the documentation that will allow me to
insert
php code inside the html code in the $message block in the mail() function.
Using the example in the help file:

<?php
/* recipients */
$to = "va***@email.add" . ", " ; // note the comma
$to .= $_POST["email_address"];

/* subject */
$subject = "CTO for {$_POST["Client_Name"]}";

/* message */
$message ='
<HTML>
<BODY>
<H1 ALIGN=CENTER><FONT SIZE=7>CTO</FONT></H1>
<HR SIZE=10 color="blue">
<DIV ALIGN=LEFT>
<P><STRONG> Todays Date:"<?php echo $_POST["Date"]; ?>"</STRONG></P>
<HR SIZE=10 color="blue">
</BODY>
</HTML>
';

/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

/* additional headers */
$headers .= "To: Department <va***@email.add>\r\n";
$headers .= "From: {$_POST["Sales_Person"]}
<{$_POST["email_address"]}>\r\n";
$headers .= "Cc: {$_POST["Sales_Person"]} <{$_POST["email_address"]}>\r\n";

/* and now mail it */
mail($to, $subject, $message, $headers);
?>
The above code displays the first line "CTO", the first HR then "Todays
Date:" and then
just a pair of double quotes. After that, the next HR and that's it.

The e-mail works fine, the script will pick-up the data from the html form
for the addresses.

Any help or direction would be appreciated.

Thanks,
Ray
To reply direct, take out spam.
Jul 17 '05 #1
7 3779
"Rainmaker" <ra*****@spammailatmydomain.com> wrote in message
news:2G****************@newssvr22.news.prodigy.com ...
Greetings,
I have not been able to find the documentation that will allow me to
insert
php code inside the html code in the $message block in the mail() function. Using the example in the help file:

<?php
/* recipients */
$to = "va***@email.add" . ", " ; // note the comma
$to .= $_POST["email_address"];

/* subject */
$subject = "CTO for {$_POST["Client_Name"]}";

/* message */
$message ='
<HTML>
<BODY>
<H1 ALIGN=CENTER><FONT SIZE=7>CTO</FONT></H1>
<HR SIZE=10 color="blue">
<DIV ALIGN=LEFT>
<P><STRONG> Todays Date:"<?php echo $_POST["Date"]; ?>"</STRONG></P>
<HR SIZE=10 color="blue">
</BODY>
</HTML>
';

/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

/* additional headers */
$headers .= "To: Department <va***@email.add>\r\n";
$headers .= "From: {$_POST["Sales_Person"]}
<{$_POST["email_address"]}>\r\n";
$headers .= "Cc: {$_POST["Sales_Person"]} <{$_POST["email_address"]}>\r\n";
/* and now mail it */
mail($to, $subject, $message, $headers);
?>
The above code displays the first line "CTO", the first HR then "Todays
Date:" and then
just a pair of double quotes. After that, the next HR and that's it.

The e-mail works fine, the script will pick-up the data from the html form
for the addresses.

Any help or direction would be appreciated.

Thanks,
Ray
To reply direct, take out spam.


thats becouse $message is a string, treat it as such, try this:
$message ='
<HTML>
<BODY>
<H1 ALIGN=CENTER><FONT SIZE=7>CTO</FONT></H1>
<HR SIZE=10 color="blue">
<DIV ALIGN=LEFT>
<P><STRONG> Todays Date:{$_POST["Date"]}</STRONG></P>
<HR SIZE=10 color="blue">
</BODY>
</HTML>
';

--
Mike Bradley
http://gzen.myhq.info -- free online php tools
Jul 17 '05 #2

"CountScubula" <me@scantek.hotmail.com> wrote in message
news:Lt*****************@newssvr25.news.prodigy.co m...
"Rainmaker" <ra*****@spammailatmydomain.com> wrote in message
news:2G****************@newssvr22.news.prodigy.com ...
Greetings,
I have not been able to find the documentation that will allow me to
insert
php code inside the html code in the $message block in the mail()

function.
Using the example in the help file:

<?php
/* recipients */
$to = "va***@email.add" . ", " ; // note the comma
$to .= $_POST["email_address"];

/* subject */
$subject = "CTO for {$_POST["Client_Name"]}";

/* message */
$message ='
<HTML>
<BODY>
<H1 ALIGN=CENTER><FONT SIZE=7>CTO</FONT></H1>
<HR SIZE=10 color="blue">
<DIV ALIGN=LEFT>
<P><STRONG> Todays Date:"<?php echo $_POST["Date"]; ?>"</STRONG></P>
<HR SIZE=10 color="blue">
</BODY>
</HTML>
';

/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

/* additional headers */
$headers .= "To: Department <va***@email.add>\r\n";
$headers .= "From: {$_POST["Sales_Person"]}
<{$_POST["email_address"]}>\r\n";
$headers .= "Cc: {$_POST["Sales_Person"]}

<{$_POST["email_address"]}>\r\n";

/* and now mail it */
mail($to, $subject, $message, $headers);
?>
The above code displays the first line "CTO", the first HR then "Todays
Date:" and then
just a pair of double quotes. After that, the next HR and that's it.

The e-mail works fine, the script will pick-up the data from the html form for the addresses.

Any help or direction would be appreciated.

Thanks,
Ray
To reply direct, take out spam.


thats becouse $message is a string, treat it as such, try this:
$message ='
<HTML>
<BODY>
<H1 ALIGN=CENTER><FONT SIZE=7>CTO</FONT></H1>
<HR SIZE=10 color="blue">
<DIV ALIGN=LEFT>
<P><STRONG> Todays Date:{$_POST["Date"]}</STRONG></P>
<HR SIZE=10 color="blue">
</BODY>
</HTML>
';

--
Mike Bradley
http://gzen.myhq.info -- free online php tools


Greetings,
Mike, I appreciate your reply to my post.
Unfortunately that recommendation did not work. It printed out:
Todays Date: {$_POST["Date"]}.
I tried putting the php script tag in, like this:
Todays Date:<?php {$_POST["Date"]}?>
but that printed out:
Todays Date:

If you or someone else has another suggestion or a place to look
I would very much appreciate it.

Thank you,
Ray
Jul 17 '05 #3
Greetings,
Mike, I appreciate your reply to my post.
Unfortunately that recommendation did not work. It printed out:
Todays Date: {$_POST["Date"]}.
I tried putting the php script tag in, like this:
Todays Date:<?php {$_POST["Date"]}?>
but that printed out:
Todays Date:

If you or someone else has another suggestion or a place to look
I would very much appreciate it.

Thank you,
Ray


Was "Date" set from a form that got POSTed to your page? I was mearly
correcting the error in the string definition, not validity of it.

if you want the date use:
Todays Date:<?php print date("j, n, Y"); ?>
--
Mike Bradley
http://gzen.myhq.info -- free online php tools
Jul 17 '05 #4

"CountScubula" <me@scantek.hotmail.com> wrote in message
news:b3*****************@newssvr27.news.prodigy.co m...
Greetings,
Mike, I appreciate your reply to my post.
Unfortunately that recommendation did not work. It printed out:
Todays Date: {$_POST["Date"]}.
I tried putting the php script tag in, like this:
Todays Date:<?php {$_POST["Date"]}?>
but that printed out:
Todays Date:

If you or someone else has another suggestion or a place to look
I would very much appreciate it.

Thank you,
Ray


Was "Date" set from a form that got POSTed to your page? I was mearly
correcting the error in the string definition, not validity of it.

if you want the date use:
Todays Date:<?php print date("j, n, Y"); ?>
--
Mike Bradley
http://gzen.myhq.info -- free online php tools


Greetings,

Thanks again Mike for replying.

The data, including the date, is coming from an html form. I'm using the
mail()
script from the php help file:

<?php
/* recipients */
$to = "ma**@example.com" . ", " ; // note the comma
$to .= "ke***@example.com";

/* subject */
$subject = "Birthday Reminders for August";

/* message */
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';

/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

/* additional headers */
$headers .= "To: Mary <ma**@example.com>, Kelly <ke***@example.com>\r\n";
$headers .= "From: Birthday Reminder <bi******@example.com>\r\n";
$headers .= "Cc: bi*************@example.com\r\n";
$headers .= "Bcc: bi***********@example.com\r\n";

/* and now mail it */
mail($to, $subject, $message, $headers);
?>

with the data from the html form being included in the $message block in
the above script.
I've tried your suggestions and the <script language=php> </script> escape
tags but nothing
works yet.

Thank you,
Ray
Jul 17 '05 #5
If you use 'single quotes' any variable e.g. $var will just display $var a
text string not the value it references. That is why you are getting
{$_POST["Date"]} output as a string. To use variables in a string you should
use "double quotes" as PHP recognises variables inside double quotes. When
you use double-quotes, however, any further use of double-quotes inside your
string must be "escaped" using the \ character. You do not need <?php ?>
here but put the Date in single quotes as the escape character \ does not
seem to work here. Also you appear to need to put the braces in too (I got
this by trial and error mainly and not entirely sure of the whys and
wherefores and there may be other ways of doing it - I am a newcomer to PHP)

Hence your code should read:

$message ="
<HTML>
<BODY>
<H1 ALIGN=CENTER><FONT SIZE=7>CTO</FONT></H1>
<HR SIZE=10 color=\"blue\">
<DIV ALIGN=LEFT>
<P><STRONG> Todays Date: {$_POST['Date']}</STRONG></P>
<HR SIZE=10 color=\"blue\">
</BODY>
</HTML>
";

Hope that works as I did not have time to test it properly.

Mark
"Rainmaker" <ra*****@spammailatmydomain.com> wrote in message
news:2G****************@newssvr22.news.prodigy.com ...
Greetings,
I have not been able to find the documentation that will allow me to
insert
php code inside the html code in the $message block in the mail() function. Using the example in the help file:

<?php
/* recipients */
$to = "va***@email.add" . ", " ; // note the comma
$to .= $_POST["email_address"];

/* subject */
$subject = "CTO for {$_POST["Client_Name"]}";

/* message */
$message ='
<HTML>
<BODY>
<H1 ALIGN=CENTER><FONT SIZE=7>CTO</FONT></H1>
<HR SIZE=10 color="blue">
<DIV ALIGN=LEFT>
<P><STRONG> Todays Date:"<?php echo $_POST["Date"]; ?>"</STRONG></P>
<HR SIZE=10 color="blue">
</BODY>
</HTML>
';

/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

/* additional headers */
$headers .= "To: Department <va***@email.add>\r\n";
$headers .= "From: {$_POST["Sales_Person"]}
<{$_POST["email_address"]}>\r\n";
$headers .= "Cc: {$_POST["Sales_Person"]} <{$_POST["email_address"]}>\r\n";
/* and now mail it */
mail($to, $subject, $message, $headers);
?>
The above code displays the first line "CTO", the first HR then "Todays
Date:" and then
just a pair of double quotes. After that, the next HR and that's it.

The e-mail works fine, the script will pick-up the data from the html form
for the addresses.

Any help or direction would be appreciated.

Thanks,
Ray
To reply direct, take out spam.

Jul 17 '05 #6

"Fnark" <fa**@reallyisfake.com> wrote in message
news:p7******************@news-binary.blueyonder.co.uk...
If you use 'single quotes' any variable e.g. $var will just display $var a
text string not the value it references. That is why you are getting
{$_POST["Date"]} output as a string. To use variables in a string you should use "double quotes" as PHP recognises variables inside double quotes. When
you use double-quotes, however, any further use of double-quotes inside your string must be "escaped" using the \ character. You do not need <?php ?>
here but put the Date in single quotes as the escape character \ does not
seem to work here. Also you appear to need to put the braces in too (I got
this by trial and error mainly and not entirely sure of the whys and
wherefores and there may be other ways of doing it - I am a newcomer to PHP)
Hence your code should read:

$message ="
<HTML>
<BODY>
<H1 ALIGN=CENTER><FONT SIZE=7>CTO</FONT></H1>
<HR SIZE=10 color=\"blue\">
<DIV ALIGN=LEFT>
<P><STRONG> Todays Date: {$_POST['Date']}</STRONG></P>
<HR SIZE=10 color=\"blue\">
</BODY>
</HTML>
";

Hope that works as I did not have time to test it properly.

Mark
"Rainmaker" <ra*****@spammailatmydomain.com> wrote in message
news:2G****************@newssvr22.news.prodigy.com ...
Greetings,
I have not been able to find the documentation that will allow me to
insert
php code inside the html code in the $message block in the mail()

function.
Using the example in the help file:

<?php
/* recipients */
$to = "va***@email.add" . ", " ; // note the comma
$to .= $_POST["email_address"];

/* subject */
$subject = "CTO for {$_POST["Client_Name"]}";

/* message */
$message ='
<HTML>
<BODY>
<H1 ALIGN=CENTER><FONT SIZE=7>CTO</FONT></H1>
<HR SIZE=10 color="blue">
<DIV ALIGN=LEFT>
<P><STRONG> Todays Date:"<?php echo $_POST["Date"]; ?>"</STRONG></P>
<HR SIZE=10 color="blue">
</BODY>
</HTML>
';

/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

/* additional headers */
$headers .= "To: Department <va***@email.add>\r\n";
$headers .= "From: {$_POST["Sales_Person"]}
<{$_POST["email_address"]}>\r\n";
$headers .= "Cc: {$_POST["Sales_Person"]}

<{$_POST["email_address"]}>\r\n";

/* and now mail it */
mail($to, $subject, $message, $headers);
?>
The above code displays the first line "CTO", the first HR then "Todays
Date:" and then
just a pair of double quotes. After that, the next HR and that's it.

The e-mail works fine, the script will pick-up the data from the html form for the addresses.

Any help or direction would be appreciated.

Thanks,
Ray
To reply direct, take out spam.



Greetings,

Mark, thank you for your reply. That was indeed the problem. I switched
to
the double quotes to enclose the entire $message string and all the data is
appearing
as it should.
Thanks to you and Mike for all your help.

Ray
Jul 17 '05 #7
"Fnark" <fa**@reallyisfake.com> wrote in message
news:p7******************@news-binary.blueyonder.co.uk...
If you use 'single quotes' any variable e.g. $var will just display $var a
text string not the value it references. That is why you are getting
{$_POST["Date"]} output as a string. To use variables in a string you should use "double quotes" as PHP recognises variables inside double quotes. When
you use double-quotes, however, any further use of double-quotes inside your string must be "escaped" using the \ character. You do not need <?php ?>
here but put the Date in single quotes as the escape character \ does not
seem to work here. Also you appear to need to put the braces in too (I got
this by trial and error mainly and not entirely sure of the whys and
wherefores and there may be other ways of doing it - I am a newcomer to

PHP)

Ah yes,

I tend to get sooooo involved in a piece a code, I tend to miss what is
right there in my face.

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Juha Suni | last post by:
Hi! I have managed to live without using too much regular expressions so far, and now that I need one, I need some help too. I have a string containing a (possibly large) block of html. I need...
0
by: Dafella | last post by:
The following is code from Xeoport. It is suppose to access my pop3 account and load email into Mysql database. It's not inserting and there is no log or anything to tell me why. Here is the...
6
by: dmiller23462 | last post by:
Here is the code, it's not complete of course....I've been inserting lines as I go to pinpoint the issue.....I understand that the error message I'm getting (#185 Missing Default Property) is...
5
by: Shane | last post by:
Thanks in advance for the help. I'm new to the STL and havig a bit of trouble figuring out the whole iterator thing. I am using the <list> template and I can insert elements into the list just...
8
by: Jimmy Smits | last post by:
Hi I have been playing with some JS that I cut from another page. It is a NCAA tournament bracket. When the user clicks on the submit button it sends the predictions to a db I have created. I got...
2
by: Alan Silver | last post by:
Hello, VWD Express seems obsessed with inserting loads of spaces at the start of each line whenever you drag controls into the source view. I guess this is MS' idea of making the source code...
14
by: hgraham | last post by:
Hi, I'm trying to understand how to work the dom, and all I'm trying to do is insert a link right before another link in the html based on it's href value. This isn't a real world example - I'm...
13
by: Vesuvius2001 | last post by:
hi im wondering is anyone can help me with this peice of code what i am trying todo is to create a register page where users type information which goes into a database heres the code FORM CODE...
4
by: Steve | last post by:
Can someone help me with this code - I'm trying to retrieve updated product information by pulling 3 fields and inserting values into my MYSQL db. In my code below I'm getting the page but I can't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.