Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Special characters added in Email rending in Outlook

the mail() function

Moderators: macek, egami, gesf

Special characters added in Email rending in Outlook

Postby mkb25 » Sun Jan 29, 2012 9:24 am

Hi,

I am facing a very strange issue... The issue is:

On click of Submit button of the HTML Form, on the server side I am storing all values in to memory variables and dispatching an Email.

The email is correctly dispatched.

Email content is properly rendered in an Gmail Account. But when viewing the email contents in Microsoft Outlook, foreign characters are added to certain fields in the Email.

Here is the PHP code for Email I am using:

Code: Select all
<?php
$to ='test@open-source-varsity.com';

$subject = "Testing";

$message = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>' . $subject . '</title></head>
<body style="font-family: Verdana, Arial, Helvetica, sans-serif; color: #000000; font-size: 10pt;">
   <fieldset style="width:700px;">
      <legend>&nbsp; <strong>Personal Information</strong> &nbsp;</legend>
      <table width="100%" cellspacing="0" border="1" cellpadding="5" align="left">
         <tr>
            <td align="right" style="font-size: 10pt;" width="30%"><strong>Title:</strong></td>
            <td align="left" style="font-size: 10pt;" width="70%">'.$m_title.' </td>
         </tr>
         <tr>
            <td align="right" style="font-size: 10pt;" width="30%"><strong>First Name:</strong></td>
            <td align="left" style="font-size: 10pt;" width="70%">'.$m_fname.' </td>
         </tr>
         <tr>
            <td align="right" style="font-size: 10pt;" width="30%"><strong>Middle Name:</strong></td>
            <td align="left" style="font-size: 10pt;" width="70%">'.$m_mname.' </td>
         </tr>
         <tr>
            <td align="right" style="font-size: 10pt;" width="30%"><strong>Last Name:</strong></td>
            <td align="left" style="font-size: 10pt;" width="70%">'.$m_lname.' </td>
         </tr>
         <tr>
            <td align="right" style="font-size: 10pt;" width="30%"><strong>Address:</strong></td>
            <td align="left" style="font-size: 10pt;" width="70%">'.$m_address.' </td>
         </tr>
         <tr>
            <td align="right" style="font-size: 10pt;" width="30%"><strong>Email Address:</strong></td>
            <td align="left" style="font-size: 10pt;" width="70%">'.$m_email_id.' </td>
         </tr>
         <tr>
            <td align="right" style="font-size: 10pt;" width="30%"><strong>Confirm Email Address:</strong></td>
            <td align="left" style="font-size: 10pt;" width="70%">'.$m_confirm_email_id.' </td>
         </tr>
      </table>
   </fieldset>
   <div class="divClr" style="clear:both;">&nbsp;</div>
</body>
</html>';

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

/* additional headers */
$headers .= "To: " . $to ." \n";

/* and now mail it */
if(mail($to, $subject, $message, $headers))
{
   $status = "Sent";
}
?>


Output of the above in Outlook as shown in diagram below:
email_in_outlook.png
Email in Outlook
email_in_outlook.png (47.83 KiB) Viewed 409 times


This has never happen before. Please can some one help me.

Thanks a lot.

Regards,

Meher K Bala
http://www.open-source-varsity.com
mkb25
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sun Jan 29, 2012 8:52 am

Re: Special characters added in Email rending in Outlook

Postby TheProdigyGuy » Sun Jan 29, 2012 1:22 pm

Hello Meher K Bala.
I changed your encoding to UTF-8(line no: 47 and 48)
Should work and Should handle correctly:

Code: Select all
<?php
$to ='test@open-source-varsity.com';

$subject = "Testing";

$message = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>' . $subject . '</title></head>
<body style="font-family: Verdana, Arial, Helvetica, sans-serif; color: #000000; font-size: 10pt;">
   <fieldset style="width:700px;">
      <legend>&nbsp; <strong>Personal Information</strong> &nbsp;</legend>
      <table width="100%" cellspacing="0" border="1" cellpadding="5" align="left">
         <tr>
            <td align="right" style="font-size: 10pt;" width="30%"><strong>Title:</strong></td>
            <td align="left" style="font-size: 10pt;" width="70%">'.$m_title.' </td>
         </tr>
         <tr>
            <td align="right" style="font-size: 10pt;" width="30%"><strong>First Name:</strong></td>
            <td align="left" style="font-size: 10pt;" width="70%">'.$m_fname.' </td>
         </tr>
         <tr>
            <td align="right" style="font-size: 10pt;" width="30%"><strong>Middle Name:</strong></td>
            <td align="left" style="font-size: 10pt;" width="70%">'.$m_mname.' </td>
         </tr>
         <tr>
            <td align="right" style="font-size: 10pt;" width="30%"><strong>Last Name:</strong></td>
            <td align="left" style="font-size: 10pt;" width="70%">'.$m_lname.' </td>
         </tr>
         <tr>
            <td align="right" style="font-size: 10pt;" width="30%"><strong>Address:</strong></td>
            <td align="left" style="font-size: 10pt;" width="70%">'.$m_address.' </td>
         </tr>
         <tr>
            <td align="right" style="font-size: 10pt;" width="30%"><strong>Email Address:</strong></td>
            <td align="left" style="font-size: 10pt;" width="70%">'.$m_email_id.' </td>
         </tr>
         <tr>
            <td align="right" style="font-size: 10pt;" width="30%"><strong>Confirm Email Address:</strong></td>
            <td align="left" style="font-size: 10pt;" width="70%">'.$m_confirm_email_id.' </td>
         </tr>
      </table>
   </fieldset>
   <div class="divClr" style="clear:both;">&nbsp;</div>
</body>
</html>';

/* To send HTML mail, set the Content-type header. */
$headers = "MIME-Version: 1.0". PHP_EOL;
$headers .= "Content-type: text/html; charset=UTF-8" . PHP_EOL;

/* additional headers */
$headers .= "To: " . $to ." \n";

/* and now mail it */
if(mail($to, $subject, $message, $headers))
{
   $status = "Sent";
}
?>
TheProdigyGuy
New php-forum User
New php-forum User
 
Posts: 215
Joined: Wed Dec 07, 2011 5:25 pm

Re: Special characters added in Email rending in Outlook

Postby mkb25 » Sun Jan 29, 2012 7:49 pm

Hi TheProdigyGuy,

Thanks a lot for your help and it worked... Really appreciate the quick reply.

Please may I know why u added PHP_EOL in the header ?

What is the purpose of using PHP_EOL in the header ?

Regards,

Meher K Bala
http://www.opensourcevarsity.com
mkb25
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sun Jan 29, 2012 8:52 am


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.