Forum Moderators: coopster

Message Too Old, No Replies

setting a variable to HTML code

         

mutechguy

7:43 pm on May 21, 2008 (gmt 0)

10+ Year Member



Hello, this is my first time posting here, I have recently been using these forums to help me write my first PHP script. I apologize if some of my jargon isn't correct, I am really new to all this. Also, this post is really long, sorry about that too.

A little background info. The end goal for this is to make a service receipt for the company I work for so that you can fill it out and then two emails are sent, one to me, and one to the customer filling it out. That aspect works correctly, however I now need to make it "look pretty". The way I would like to do this is simply take the HTML from the service receipt itself, input the variables so that the info filled in shows up. The problem I am experiencing is that when I try to set $MailBody = (the html i want to show up) I either receive a parsing error of some form, or when I try it in other ways it take the HTML literally so that the code itself shows up.

My code looks a little something like this (just including the important stuff):
<?php
$MailBody = "<html>

<head>
<style type="text/css">
.style1 {
text-align: left;
}
</style>
</head>

<body>
<img width="245" height="101" src="clip_image001.JPG" v:shapes="_x0000_i1025" /><![endif]></p>
<p class="MsoNormal" align="center"><b>
<span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">420 ROUTE 46 <o:p></o:p>
</span></b></p>
<p class="MsoNormal" align="center"><st1:place w:st="on"><st1:City
w:st="on"><b>
<span style="font-family:&quot;Arial&quot; ,&quot;sans-serif&quot;">FAIRFIELD</span></b></st1:City><b><span style="font-family:&quot;Arial&quot; ,&quot;sans-serif&quot;">, <st1:State w:st="on">
NJ</st1:State>
<st1:PostalCode w:st="on">07004</st1:PostalCode></span></b></st1:place><b><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"><o:p></o:p></span></b></p>
<p class="MsoNormal" align="center"><b style="mso-bidi-font-weight:
normal"><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">
888-868-8324 Tel / 973-836-0434 Fax</span></b></p>
<p class="MsoNormal" align="center"><b style="mso-bidi-font-weight:
normal">
<span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#002060">
<a href="http://www.example.com">www.example.com</a><o:p>
</span></b></p>
<p class="style1"><b style="mso-bidi-font-weight:
normal">
<span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#002060">
Date
<input name="Date" type="text" style="width: 245px" value="$Date" /></p>
<p class="style2">Time In<input name="TimeIn" type="text" style="width: 245px" value="$TimeIn" /></p>
<p class="style2">Time Out<input name="TimeOut" type="text" style="width: 245px" value="$TimeOut" /></p>
</font></span>
<p class="style2">Cus<label id="Label9"></label>tomer <label id="Label10"> </label>
<input name="Customer" type="text" style="width: 245px" value="$Customer" /></p>
<p class="style2">Customer Email
<input name="CustomerEmail" type="text" style="width: 245px" value="$CustomerEmail" />
</p>
<p class="style2">Reason For Visit </p>

<span LANG="EN"><font FACE="Calibri" SIZE="3">
<input name="ReasonForVisit" type="text" style="width: 556px; height: 89px" value="$ReasonForVisit" /></font></span><p class="style2">Services Rendered </p>
<input name="ServicesRendered" type="text" style="width: 556px; height: 89px" value="$ServicesRendered" />
<br>
<br>
Parts SuppliedPart , Quantity</p>
<input name="Part1" type="text" style="width: 514px" value="$Part1" /><input name="Part2" type="text" style="width: 514px" value="$Part2" /><input name="Part3" type="text" style="width: 514px" value="$Part3" /><input name="Part4" type="text" style="width: 514px" value="$Part4" />
<br>
Technicians On Site:
<input name="AndrewFisherCheck" type="checkbox" value="$Andrew" /> Andrew Fisher</p>
<p class="style2"><input name="EricMunozCheck" type="checkbox" value="$Eric" /> Eric Munoz </p>

<span LANG="EN"><font FACE="Calibri" SIZE="3">
<p class="style2"><span LANG="EN"><font FACE="Calibri" SIZE="3">
<input name="JuniorBatistaCheck" type="checkbox" value="$Junior" /></font></span>Junior Batista</p>
<p class="style2">
<input name="MichaelMunozCheck" type="checkbox" value="$Michael" /> Michael Munoz</p>
<p class="style2">

<span LANG="EN"><font FACE="Calibri" SIZE="3">
<input name="OliverCarrasquilloCheck" type="checkbox" value="$Oliver" /></font></span> Oliver Carrasquillo</p>
<input name="Submit1" type="submit" value="Submit" /></font></span>
</b>
</body>
</html>";

mail("andrew@example.com,".$email, "Service Receipt",
$MailBody, "From: receiptghost@example.com" );
header( "Location: confirmation.html" );
?>

I know the code is really sloppy, I designed it in frontpage. If you have made it this far, thank you, and thanks in advance for your help.
-Mutechguy

[edited by: eelixduppy at 4:00 pm (utc) on May 22, 2008]
[edit reason] please use example.com [/edit]

chorny

8:07 pm on May 21, 2008 (gmt 0)

10+ Year Member



Use templates or at least heredocuments. And read a good book about PHP. Contrary to popular belief, you can't program in PHP without knowing the language.

Demaestro

9:11 pm on May 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The reason for your parse errors is that you are using double quotes within the HTML string..

So when you say:

$MailBody = "<html></html>"

The Output of Mailbody is : <html></html>

When you add " into the string then you cause problems.

$MailBody = "<html this="that"></html>"

The Output of Mailbody is : <html this=

Because it only uses what is in between the double quotes...

You need to change the double quotes in your html to single quotes and that will solve your problem

So....

$MailBody = "<html this='that'></html>"

The Output of Mailbody is : <html this='that'></html>

Hope this helps

PHP_Chimp

9:14 pm on May 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are trying to echo a large amount of text/html then heredocs are very useful. As you can use both " and ' and not have to worry about escaping either.

Have a look at the echo [uk.php.net] section of the manual.
They can save a huge amount of time...and a lot easier to write ;)

dreamcatcher

2:53 pm on May 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld mutechguy. :)

dc

mutechguy

3:03 pm on May 22, 2008 (gmt 0)

10+ Year Member



I changed up the quotes and I no longer get parse errors, however it is still just sending the email as literal code.

When I try to set it up using echo I get parse errors. I feel like the problem is that I am just being stupid, however no matter what way I try it the results are either an error or straight code in my email. Both of the email accounts I am sending it to should be able to read HTML also so I know that is not the issue.

Thanks for the welcome, and thanks for the help :).

eelixduppy

3:09 pm on May 22, 2008 (gmt 0)



Try adding another header:

mail("andrew@example.com,".$email, "Service Receipt",
$MailBody, "From: receiptghost@example.com\r\n".'Content-type: text/html; charset=iso-8859-1' . "\r\n");

Should do the trick :)

And welcome to WebmasterWorld!

mutechguy

3:47 pm on May 22, 2008 (gmt 0)

10+ Year Member



Thank you so much eelixduppy, you are my hero.

Im pretty sure my problem is resolved, but Im sure Ill be back.

Thanks again

-mutechguy