2

I am following a tutorial http://css-tricks.com/sending-nice-html-email-with-php/ to send mail in html format.

My string looks like

$message = '<html><body>';
$message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Dear:</strong> </td><td>" . strip_tags($part_name). "</td></tr>";
$message .= "<tr><td><strong>.$user_name.has fixed an appointment with you on  :</strong> </td><td>" . strip_tags($time). "</td></tr>";
$message .= "<tr><td><strong>In:</strong> </td><td>" .  strip_tags($meeting_name) . "</td></tr>";
$message .= "<tr><td><strong>Please click on:</strong> </td><td><a href=" . strip_tags($approve_url). "</a> To approve</td></tr>";
$message .= "</table>";
$message .= "</body></html>";

//   CHANGE THE BELOW VARIABLES TO YOUR NEEDS

$subject = 'Appointment Request ';

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

But the received mail is not html formatted it is looking like

<html>
    <body>
        <img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />
        <table rules="all" style="border-color: #666;" cellpadding="10">
            <tr style='background: #eee;'>
                <td>
                    <strong>Dear:</strong> 
                </td>
                <td>Depu</td>
            </tr>
            <tr>
                <td>
                    <strong>.pandit.has fixed an appointment with you on  :</strong> 
                </td>
                <td>
                </td>
            </tr>
            <tr>
                <td>
                    <strong>In:</strong>
                </td>
                <td>anyp</td>
            </tr>
            <tr>
                <td>
                    <strong>Please click on:</strong>
                </td>
                <td>
                    <a href=http://192.168.0.178/UI/user/approvemeeting.php?meetingid=REG_939300945&key=3107</a> To approve
                </td>
            </tr>
        </table>
    </body>
</html>

Please tell me what i am doing wrong why the mail is not coming html formatted

5
  • how are you sending the email? Commented Aug 20, 2012 at 10:07
  • $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, '[email protected]', $pr_email, $subject, $message); $SMTPChat = $SMTPMail->SendMail(); Commented Aug 20, 2012 at 10:08
  • 1
    what is SMTPClient? you don't seem to be passing headers to it. Commented Aug 20, 2012 at 10:16
  • Also, please note that your mail client (program/site you view your mails in) must support HTML emails or have them enabled, although this is probably not the problem, since most clients support it. Commented Aug 20, 2012 at 10:36
  • yeah thanks to all for comments and suggestions Commented Aug 20, 2012 at 10:38

2 Answers 2

2

From:

$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, '[email protected]', $pr_email, $subject, $message); $SMTPChat = $SMTPMail->SendMail(); 

You are never sending in the $headers var as such the email has no headers and as such the MIME type will not be read by the mail client on the other end.

I do not understand the SMTPClient class and judging form the tutorial I recommend you prolly shouldn't use it since it is opening a socket directly to the SMTP server. Also this class does not actually support custom headers which sucks. mail() will use your default SMTP server.

Sign up to request clarification or add additional context in comments.

Comments

1

Use PHPMailer instead.

It allows you to send SMTP and normal emails (PHP's mail() function or expliciting all the SMTP params), and most important it lets you sepecify HTML message, plain text alternative message (but don't specify it otherwise some clients won't display the HTML one, such as bloody Lotus Notes).

It allows you to specify headers, mime, etc...

http://phpmailer.worxware.com/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.