dongzhabo2796 2011-09-27 15:49
浏览 30

PHP邮件:发送ÅÄÖ字符?

I'm trying to send a mail containing ÅÄÖ characters (Swedish).

I've tried changing the mail header to UTF-8 and iso-8859-1, none of which works. I've also tried wrapping the text in utf8_encode() as well as mb_encode_mimeheader(), with no success. In some cases i get chinese characters instead, not really what i want.

I just tried using htmlentities() with no result.

        $values = array(
            'name' => $this->input->post('name'),
            'email' => $this->input->post('email'),
            'ref' => $this->input->post('ref'),
            'sex' => $this->input->post('sex'),
            'age' => $this->input->post('age'),
            'question' => $this->input->post('msg'),
            'ip' => $_SERVER['REMOTE_ADDR']
        );

        $to      = '@live.se';
        $subject = $values['name'] . ' har skickat en fråga!';
        $message  = 'Namn:'.$values['name']." 
";
        $message .= "
Email:".$values['email']." 
";
        $message .= "
Kön:".(($values['sex'] == 'f') ? 'Kvinna' : 'Man')." 
";
        $message .= "
Ålder:".$values['age']." 
";
        $message .= "
Referensnummer:".$values['ref']." 
";
        $message .= "
Meddelande: 
".$values['question'];

        $headers = 'From: noreply@.se' . "
" .
            'Content-type: text/html; charset=iso-8859-1' . "
" .
            'Reply-To: ' .$this->input->post('email') . "
" .
            'X-Mailer: PHP/' . phpversion();

        $message = htmlentities($message);

        if(@mail($to, $subject, $message, $headers)) {
            if($this->input->is_ajax_request()) {
                echo 1;
            }else {

                $data['message']['header'] = 'Tack så mycket!';
                $data['message']['content'] = 'Din fråga skickades utan problem! Jag återkommer snarast möjligt.';

                echo $this->load->view('includes/header', array(), true);
                echo $this->load->view('message', $data['message'], true);
                echo $this->load->view('includes/footer', array(), true);
            }
        }else {
            $fail = true;
        }
  • 写回答

3条回答 默认 最新

  • duanqiao8925 2011-09-27 15:54
    关注

    I don't know if this is the best way to achieve this. But I used to use mail like this:

    mail($to, "=?utf-8?B?".base64_encode($subject)."?=", $message, $headers);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?