无法以html格式发送邮件

时间:2011-02-26 12:05:14

标签: php email

我正在使用php的mail()函数发送电子邮件的网站上工作。但是,由于服务器在发送HTML电子邮件时出现问题,因此电子邮件无法正常传送。请帮忙...代码如下:

<?php
$fromAddr = 'Frendzpark <admin@Frendzpark.co.cc>'; // the address to show in From field.
$recipientAddr = 'rautsanket2105@gmail.com';
$subjectStr = 'Demo:Account created successfully';

$mailBodyText = <<<HHHHHHHHHHHHHH
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Account created successfully</title>
</head>
<body>
<p>
<div style="color: #ff4e0a; height: 100px; font-weight: bold; font-size: 70px; font-family: 'Maiandra GD'; text-align: left; padding-left: 10px;">
        Chatmasti</div><hr />
    <div style="font-family: 'Trebuchet MS'; height: 160px; padding-left: 30px; font-size: 12px; border-left-width: thin; border-left-color: #ccccff; border-bottom-width: thin; border-bottom-color: #ccccff; border-right-width: thin; border-right-color: #ccccff;">
        Thank you for signing up. Your account has been created successfully and your account
        details are as follows:<br />
        <br />
        Username: <b>user</b><br />
        Password: <b>pass</b><br />
            <br />
        You can start chatting after verifying your email address. To verify the email address
        please click the link below:<br />
        <a href="http://www.chatmasti.uk.tc/verify=3973hfuhfri23892">http://www.chatmasti.uk.tc/verify=3973hfuhfri23892</a><br />
        Hope you enjoy this free service.<br />
        <br />
        Regards,<br />
        Sanket Raut.<br />
        Webmaster,<br />
        Chatmasti</div>
</p>
</body>
</html>
HHHHHHHHHHHHHH;

$headers= <<<TTTTTTTTTTTT
From: $fromAddr
MIME-Version: 1.0
Content-Type: text/html;
TTTTTTTTTTTT;

$sent=mail( $recipientAddr , $subjectStr , $mailBodyText, $headers);
if($sent)
 print "Mail sent";
else
 print "Error";

?>

2 个答案:

答案 0 :(得分:0)

我认为你需要指定字符集。在Content-Type选项后面添加charset选项,如下所示:

Content-type: text/html; charset=iso-8859-1

答案 1 :(得分:0)

也许最好使用Swift邮件解决方案,不要重新发明轮子?

http://swiftmailer.org/