dqxyh48864 2016-01-29 14:14
浏览 167

如何使用PHP向其他电子邮件服务发送电子邮件

I have a problem sending email from PHP to yahoo email when characters are in Persian. The code is:

$msg = "some persian words";
$from = "my_email@my_server.com";
$headers = "From: $from
";
$headers .= "MIME-Version: 1.0
";
$headers .= "Content-type: text/html; charset=iso-8859-1
";
$headers .= "BCC: $to".PHP_EOL;
$message =  '<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Message</title></head>
<body style="margin:0px; font-family:Tahoma, Geneva, sans-serif; font-size:12px;">
'.htmlspecialchars_decode($msg).'
<div style="margin-top:5px">Please do not reply to this email.</div>
</div></body></html>';

I don't have problem the text content sending to Gmail but in Yahoo mail the encoding Persian characters does not work and it is like this:

تناسلبر نمتاربمنت

  • 写回答

1条回答 默认 最新

  • 普通网友 2016-01-29 14:44
    关注

    you should use Mail Mime

    this is an example from the Mail Mime repository in git https://github.com/pear/Mail_Mime/blob/master/scripts/phail.php

    <?php
    /**
    * PHAIL - stands for PHP Mail
    * @author Tomas V.V.Cox <cox@idecnet.com>
    */
    require_once 'Mail.php';
    require_once 'Mail/mime.php';
    require_once 'Console/Getopt.php';
    $argv = Console_Getopt::readPHPArgv();
    $opts = Console_Getopt::getOpt($argv, 'f:c:s:t:a:b:');
    if (PEAR::isError($opts)) {
        usage($opts->getMessage());
    }
    PEAR::setErrorHandling(PEAR_ERROR_DIE);
    $mime = new Mail_mime;
    foreach ($opts[0] as $opt) {
        $param = $opt[2];
        switch ($opt[0]) {
            case 'f':
                $headers['From'] = $param; break;
            case 'c':
                $headers['Cc'] = $param; break;
            case 's':
                $headers['Subject'] = $param; break;
            case 't':
                $to = $param; break;
            case 'a':
                $mime->addAttachment($param); break;
            case 'b':
                $isfile = @is_file($param) ? true : false;
                $mime->setTXTBody($param, $isfile); break;
        }
    }
    $mbody   = $mime->get();
    $headers = $mime->headers($headers);
    $mail    = Mail::factory('mail');
    $mail->send($to, $headers, $mbody);
    function usage($error)
    {
        die($error);
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端