doufangyan6862 2012-04-13 16:41
浏览 39
已采纳

PHP上的mail()函数有奇怪的字符

I'm using the php mail function, it works kinda fine, i really don't like to use this function but will have to do for this one.

So the problem is, the special european characters are being shown in a funny way on the email, i tried to set the codification to iso-8859-1 and the same is happening:

$to = $eemail;
$subject = $campos[4];
$message = $campos[5];
$message = mb_convert_encoding($message, 'HTML-ENTITIES', 'iso-8859-1');
$from = $campos[1];
$headers = "From:".$from."
";

$headers .= "MIME-Version: 1.0
";
$headers .= "Content-Type: text/html; charset=ISO-8859-1
";
$headers .= "X-Priority: 3
";
$headers .= "X-Mailer: PHP". phpversion() ."
";

The rest is a basic mail form, sent through AJAX:

$(function() {  
  $(".submita").click(function() {        
      var nome = $('#nome').attr('value');
      var email = $('#email').attr('value');
      var telemovel = $('#telemovel').attr('value');
      var loja = $('#loja').attr('value');
      var assunto = $('#assunto').attr('value');
      var mensagem = $('#mensagem').attr('value');

      var dataString = 'nome='+ nome + '&email=' + email + '&telemovel=' + telemovel + '&loja=' + loja + '&assunto=' + assunto + '&mensagem=' + mensagem;
      $.ajax({
    type: "POST",
    url: "ajaxload/conemail.php",
    data: dataString,
    success: function() {
        $(".mensagem").fadeIn();
      }
      });
      return false;
  }); 
});

What is going wrong?

  • 写回答

2条回答 默认 最新

  • dtrj74376 2012-04-13 16:46
    关注

    chk this link from php.net

    http://php.net/manual/en/function.mail.php
    

    Hope this helps, this is the small content from this php.net page I gave url of

    Sending messages with polish special characters:
    <?php
    function plmail($mail, $sub, $mes){
        $headers = "From: ExRobot <robot@example.com>
    ";
        $headers .= "MIME-Version: 1.0
    "; 
        $headers .= "Content-type: text/plain; charset=utf-8
    ";
        $headers .="Content-Transfer-Encoding: 8bit";
    
        $mes=htmlspecialchars_decode($mes,ENT_QUOTES);//optional - I use encoding to POST data
        mail($mail, "=?utf-8?B?".base64_encode($sub)."?=", $mes, $headers);
    }
    ?>
    Page must be in utf-8 encoding.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类