Page 1 of 1

how to apply css for subject in mail function

Posted: Fri Aug 27, 2010 5:40 am
by jsshanthi
Hi,

I have a form after successful submission a mail is forwarded to a particular member , this part is completed successfully but the format of the form details must be dispayed in a table format and i just want to know how to display in table form and how to apply css for the text .

Please suggest me
Thank you

Re: how to apply css for subject in mail function

Posted: Fri Aug 27, 2010 6:03 am
by ChrisBull
If no one replies to this who knows the answer i suggest you look at these tutorials, im pretty sure it goes through that in them but i have not watched them yet.
http://www.developphp.com/view.php?tid=480

Re: how to apply css for subject in mail function

Posted: Fri Aug 27, 2010 1:48 pm
by devarishi
jsshanthi wrote:Hi,

I have a form after successful submission a mail is forwarded to a particular member , this part is completed successfully but the format of the form details must be dispayed in a table format and i just want to know how to display in table form and how to apply css for the text .

Please suggest me
Thank you

Hi,

I have done that in a project i worked on on my own. I can forward you the script I used. But right now I am in a different project so I have not got it with me. So, I give you an idea here:


First, you need to set the proper MIME type to include HTML/text.

Secondly, create a variable and name it (or whatever you would): $msgBody

Code: Select all

$msgBod = '<HTML>
<head>
<style type="text/css">

<define your CSS for table and its sub-tags here>

table{
 background-color: GREEN; color: RED;
}

</style>
</head>

<p>Your Email Message goes here.
<table>
<tr>
<th>Employee Name</th>
</tr>

<tr>
<td>Mr. X</td>
</tr>
<tr>
<td>Mr. Y</td>
</tr>

</table>

</HTML>';

Now use $msgBod in your mail() function. But specify the MIME type in the headers before you do that.

If you still need more help then please feel free to contact me.

Re: how to apply css for subject in mail function

Posted: Sat Aug 28, 2010 7:28 am
by ChrisBull
How to do set the MIME type?

Sending Email in HTML Format with PHP mail() Function

Posted: Sat Aug 28, 2010 6:01 pm
by devarishi
ChrisBull wrote:How to do set the MIME type?
Okay, I am at home now. So, I just found it all for you:

Code: Select all

<?php

$message = "
	<html>
	<body>

	<p>This is an auto-generated email.</p>

	</body>
	</html>	

	";

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Service <service@company.com>;" . "\r\n";
$headers .= 'Cc: Others@company.com' . "\r\n";


$to 	= "people@company.com,managers@company.com";

$status = @mail($to,"Test Email", $message, $headers);



if ($status) {
	echo "<center><img src='success.jpg' border=0 title='Email Alert Sent' alt='Email Image'></center>";
	echo "<center><b>Note:</b> Do Not Hit the F5 Key Nor Refresh This Web Page</center>";
}

else {

	echo "<center><img src='error.jpg' border=0 title='Email Sent' alt='Sending Emails Failed!'></center>";
	echo "<center><b>Note:</b><br />There was an unexpected error while sending email alert.<br /> Do Not Hit the F5 Key Nor Refresh This Web Page</center>";

}


?>

Since I didn't need CSS in this email body so I didn't include it. You can include:

Code: Select all

<head>
<style type='text/css'>
</style>
</head>
just after the

Code: Select all

<html>
tag.


Here is an example I have created for you:

[text]sampleCSS.html[/text]

Code: Select all

<html>
<body>

<head>

<style type='text/css'>

	p {

		background-color: YELLOW;
		color: GREEN;
	}

	table {

		border: 2px;
		background-color: SILVER; 
	}

	th {
	
		background-color: GREEN; color: WHITE;			

	}

	td {
	
		color: BLACK;			

	}


</style>

</head>

<p>computer Programming Languages and Platform Support</p>


<table>

<tr>
	<th>Programming Languages</th>
	<th>Operating System</th>
</tr>

<tr>
	<td>C</td>
	<td>Windows / UNIX</td>
</tr>

<tr>
	<td>PHP</td>
	<td>Windows / UNIX</td>
</tr>

<tr>
	<td>.Net</td>
	<td>Windows</td>
</tr>


</table>

</body>
</html>

It has got CSS for Table in HTML. Just as you wanted things to be. Now apply your creativity. Store the above tags in the variable $message and see the output. If any unexpected behaviour / output is observed then post it here. I or someone else will help you.