dsljpwi494719 2013-05-21 23:32
浏览 41
已采纳

PHP邮件功能缺少字符

I have a really weird error with the mail() function in php.

This is the code i'm using to send the message:

        $to = strip_tags($_POST['newMail']);
        $subject = "Company: Update your email address ";
        $message = $mailHeader.'<b>Hello from Company!</b><br/> <br/> Please confirm your new email address by clicking this link: <a href="http://www.Company.com/confirm.php?regID='.$regID.'&newemail='.mysql_escape_string($_POST['newMail']).'" class="link"> Confirm Email Address Change</a><br/><br/><p class="p"><b>Thank you.</b></p><br/><b class="h2">Company.</b>'.$mailFooter;
        $from = "<noreply@company.com>";
        $headers = "MIME-Version: 1.0
";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1
";
        $headers .= "From: Company Name" . $from. " 
";

To note, the company name has been replaced with 'company'.

EDIT - $mailHeader

    <html>
<style>
/* `XHTML, HTML4, HTML5 Reset
----------------------------------------------------------------------------------------------------*/

body {
  border: 0;
  margin: 0;
  padding: 0;
  font-size: 100%;
}

html,
body {
  height: 100%;
}

.link{
    color:#81c6f6;
    text-decoration:none;
}
.link:visited {
    color:#81c6f6;
}
.link:hover {
    color:#f6b181;
}
.h1{
    color:#696969;
    font:20px/1.5 Helvetica, Geneva, sans-serif;
}
.p{
    padding:2px;
    color:#787878;
    font:16px/1.5 Tahoma, Geneva, sans-serif;
}
.h2{
    padding:2px;
    color:#81c6f6;;
    font:16px/1.5 Tahoma, Geneva, sans-serif;
}
.roundAll{
    -moz-border-radius:20px;
    border-radius:20px;
    -webkit-radius: 20px;
}
#header{
    height:71px;
    width:100%;
    background-color:#99d1f8;
}
#automarginwrap{
    width:90%;
    margin:0 auto;
    text-align:center;
}
#content{
    margin:0 auto;
    padding:10px;
    width:80%;
    border: solid 10px #f1f1f1;
    background-color:#fff;
}
</style>
<body>
<div id="header"><center><img src="http://www.downloadablecreations.com/images/logo.png" /></center></div>
<div id="automarginwrap">
    <div id="content" class="roundAll h1">

$mailFooter -

    </div>
</div>
</body>
</html>

Now this works fine, the mail is sent and received no error message appear, however when i click on the link, it directs me to a url missing either a 'w' in the href part of the message (Mail.app Apple):

<a href="http://ww.Company.com/confirm.php?

Or a random letter from the link:

<a href="http://www.Compay.com/confirm.php?

Am i doing something wrong?

I believe the error lies in the charset aspect of the email or the encoding.

EDIT - removing mysql_escape_string() made no difference to the result.

  • 写回答

1条回答 默认 最新

  • douli1306 2013-05-22 00:00
    关注

    Could it be that the line is longer than 70 characters? The PHP manual states that lines should be no longer than 70 characters.

    This answer may also be useful.

    Personally, I've had this problem with some email clients truncating long lines of text, similar to what you are describing. The best way to fix it would be to either break the lines apart or use a framework or method that is better equipped to send HTML mail.

    The manual recommends Pear::Mail_Mine. I would recommend something like Zend Mail if using ZF, though. Going with a framework will also help make your life much easier in the long run, especially when dealing with the many different mail servers and clients.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100