Question : Email scripting

Hi,

i am sending an email through a particular php script. The problem is there format variation in each email..

In gmail the content format is proper but it differs in rediff and yahoo and corporate mail ids..eg:[email protected],john @avaya.com....
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
<?php
session_start();
include 'dbConnect.php';

if($_POST["subSubmit"]=="Send Link to all") {
    $query="select emp_email,emp_name from empl";
    $result=mysql_query($query) or die(mysql_error());
    $num=mysql_num_rows($result);

    $email_from ="[email protected]";

    while($row=mysql_fetch_array($result)) {
        $email=$row['emp_email'];
        $emid=base64_encode($email);
        $link="http://www.xyz.com/declaration1.php?mid=$emid";
        $emailto_web     = $email;
        $email_headers   = "From: ".$email_from."\n";
        $email_headers  .= "MIME-Version: 1.0\n";
        $email_headers  .= "Content-Type: text/html; charset=iso-8859-1\n";
        $email_subject   = "INCOMETAX DECLARATIVE FORM FYI 2010-2011 (DEMO)";
        $num_sent_web    = 0;
        ob_start();
        ?>
<table style="width: 100%; font-family:Arial, Helvetica, sans-serif; font-size: 12px;">
    <tr>
        <td style="font-weight:bold">
            Dear <?php echo $row['emp_name']; ?>
        </td>
    </tr>
    <tr>
        <td>
            <p>
                With the on set of the new financial year and the Govt of India
                declaring the new Income Tax Slab, you are requested to
                submit your 'Investment Declaration' for the FY 2010-11.
            </p>
            <p>
                Kindly click on the link given below which will
                take you to a secured site where in you can input your intended investments.
            </p>
            <p>
                        <?php echo $link; ?>
            </p>
        </td>
    </tr>
    <tr>
        <td>
            <table style="width:50%; font-size:12px; font-family:Arial, Helvetica, sans-serif">
                <tr>
                    <td width="73%">
                        Income upto Rs 1.6 lakh
                    </td>
                    <td width="4%">
                        :
                    </td>
                    <td width="23%">
                        Nil
                    </td>
                </tr>
                <tr>
                    <td height="16">
                        Income upto Rs. 1.9 lakh (for women)
                    </td>
                    <td>
                        :
                  </td>
                    <td>
                        Nil
                    </td>
                </tr>
                <tr>
                    <td>
                        Income above Rs 1.6 lakh and upto Rs. 5 lakh
                    </td>
                    <td>
                        :
                    </td>
                    <td>
                        10 per cent
                    </td>
                </tr>
                <tr>
                    <td>
                        Income above Rs.5 lakh and upto Rs. 8 lakh
                    </td>
                    <td>
                        :
                    </td>
                    <td>
                        20 per cent
                    </td>
                </tr>
                <tr>
                    <td>
                        Income above Rs. 8 lakh
                    </td>
                    <td>
                        :
                    </td>
                    <td>
                        30 per cent
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td>
            <h4>
                Tax Savings (Under Sec. 80C)
            </h4>
            <p>
                Deduction of an additional amount of Rs. 20,000 allowed,
                over and above the existing limit of Rs.1 lakh on tax savings
                for investment in long-term infrastructure bonds as
                notified by the Central Government.
            </p>
            <p>
                Please update your proposed tax investments by 21st April 2010.
                The same will be incorporated in your
                tax computations from April 2010 onwards.
            </p>
            <p style="color:#ff0000;">
                Please note that proof of all declarations made on the site
                have to be submitted with HR Dept by 31st Jan 2011 failing which
                it will be assumed that you have not made any investments and
                tax will be charged as per the applicable slab and short fall
                recovered during Feb and March 2011.
            </p>
        </td>
    </tr>
    <tr>
        <td>
            <p>
                Regards, <br/>
                HR Department, <br/>
                
            </p>
        </td>
    </tr>
</table>
        <?php
        $email_message2 = ob_get_clean();
        $mail_web = mail($emailto_web,$email_subject,$email_message2,$email_headers);
        if($mail_web) {
            $query2="update empl set emp_status=1,link ='$link' where emp_email='$email'";
            $result2=mysql_query($query2) or die(mysql_error());
        }
    }
}
else if($_POST["subSubmit1"]=="Resend Remainder") {
    $query3 = "select emp_email,emp_name from empl where emp_email NOT IN(select email from emp2_taxform)";
    $query4 = mysql_query($query3) or die(mysql_error());
    while($row2 = mysql_fetch_array($query4)) {
        $email 	  	 = $row2['emp_email'];
        $emid		 = base64_encode($email);
        $link		 = "http://www.xyz.com/declaration1.php?mid=$emid";
        $emailto_web     = $email;
        $email_headers   = "From: ".$email_from;
        $email_headers  .= "MIME-Version: 1.0\n";
        $email_headers  .= "Content-Type: text/html; charset=iso-8859-1\n";
        $email_subject   = "Remainder Message";
        $num_sent_web    = 0;
        ob_start();
        ?>
<table style="width: 100%; font-family:Arial, Helvetica, sans-serif; font-size: 12px;">
    <tr>
        <td style="font-weight:bold">
            Dear <?php echo $row['emp_name']; ?>
        </td>
    </tr>
    <tr>
        <td>
            <p>
                With the on set of the new financial year and the Govt of India
                declaring the new Income Tax Slab, you are requested to
                submit your 'Investment Declaration' for the FY 2010-11.
            </p>
            <p>
                Kindly click on the link given below which will
                take you to a secured site where in you can input your intended investments.
            </p>
            <p>
                        <?php echo $link; ?>
            </p>
        </td>
    </tr>
    <tr>
        <td>
            <table style="width:50%; font-size:12px; font-family:Arial, Helvetica, sans-serif">
                <tr>
                    <td width="71%">
                        Income upto Rs 1.6 lakh
                    </td>
                    <td width="3%">
                        :
                    </td>
                    <td width="26%">
                        Nil
                    </td>
                </tr>
                <tr>
                    <td>
                        Income upto Rs. 1.9 lakh (for women)
                    </td>
                    <td>
                        :
                    </td>
                    <td>
                        Nil
                    </td>
                </tr>
                <tr>
                    <td>
                        Income above Rs 1.6 lakh and upto Rs. 5 lakh
                    </td>
                    <td>
                        :
                    </td>
                    <td>
                        10 per cent
                    </td>
                </tr>
                <tr>
                    <td>
                        Income above Rs.5 lakh and upto Rs. 8 lakh
                    </td>
                    <td>
                        :
                    </td>
                    <td>
                        20 per cent
                    </td>
                </tr>
                <tr>
                    <td>
                        Income above Rs. 8 lakh
                    </td>
                    <td>
                        :
                    </td>
                    <td>
                        30 per cent
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td>
            <h4>
                Tax Savings (Under Sec. 80C)
            </h4>
            <p>
                Deduction of an additional amount of Rs. 20,000 allowed,
                over and above the existing limit of Rs.1 lakh on tax savings
                for investment in long-term infrastructure bonds as
                notified by the Central Government.
            </p>
            <p>
                Please update your proposed tax investments by 21st April 2010.
                The same will be incorporated in your
                tax computations from April 2010 onwards.
            </p>
            <p style="color:#ff0000;">
                Please note that proof of all declarations made on the site
                have to be submitted with HR Dept by 31st Jan 2011 failing which
                it will be assumed that you have not made any investments and
                tax will be charged as per the applicable slab and short fall
                recovered during Feb and March 2011.
            </p>
        </td>
    </tr>
    <tr>
        <td>
            <p>
                Regards, <br/>
                HR Department, <br/>
                
            </p>
        </td>
    </tr>
</table>
        <?php
        $email_message2 = ob_get_clean();
        $mail_web 	 = mail($emailto_web,$email_subject,$email_message2,$email_headers);
    }

}

?> 
<form name="formexp" id="formexp" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <table width="960" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td height="222" align="left" valign="bottom" background="images/bg1.gif">
                <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="22%">&nbsp;</td>
                        <td width="536" align="center" valign="bottom"><img src="images/picture1.jpg" width="536" height="222" /></td>
                        <td align="right" valign="middle"><table width="160" border="0" align="left" cellpadding="15" cellspacing="0">
                                <tr>
                                    <td width="160" align="center" valign="middle"><img src="images/Logo.png" width="160" height="96" /></td>
                                </tr>
                            </table></td>
                    </tr>
                </table>
        </tr>
    </table>  
    <table height ="150" width="550" align ="center" border="0">

        <tr>
            <td width="18%" align="center"><span class="style18">To Send the link to all memeber at first time please click this Button </span></td>
        </tr>
        <tr>
        <tr>
            <td align="center" width="18%"><input  value="Send Link to all" type="submit" name="subSubmit" id="subSubmit" ></td>
        </tr>
        <tr>
            <td align="center" width="18%"><input  value="Resend Remainder" type="submit" name="subSubmit1" id="subSubmit1" ></td>
        </tr>
        <tr>
            <td align="center" width="18%"><font color="#FF0000">&nbsp;<?php echo $err; ?>&nbsp;</font></td>
        </tr>
    </table>
</form>

Answer : Email scripting

You will be fighting a never-ending battle if you want to send formatted HTML email messages to a number of different email clients.  The reason is simply this: there are no standards for rendering HTML and CSS in email clients.  I have been there, and I know what you will be going through.  HTML is only a part of it - there are spam filters that you must conquer, etc.

I agree with logudotcom that phpMailer is better than the PHP mail() function.  However I want to suggest a more complete solution - one that encompasses not only the formatting of the email messages, but also the successful delivery, the ability to count and track who opened the mail, etc.

Consider a service like Constant Contact.  They are embarrassingly inexpensive, quick, accurate and they have wonderful customer support.  There are competing services - you might want to compare some of the others.  The setup is easy, and most importantly, they have full-time employees who do nothing but make sure your email goes through looking just like you want no matter what the email client might be.

Best of luck with it, ~Ray
Random Solutions  
 
programming4us programming4us