在outlook

时间:2015-10-26 09:30:43

标签: php outlook vcard

我有一个PHP代码来生成vCard并将其下载为vcf文件以在Outlook中打开。它适用于英文字符但是当我尝试将名字或任何其他数据更改为阿拉伯语时,生成的vCard在outlook中打开,其中outlook中包含错误或虚拟字符。我甚至试过换到不同的字符集,但我没有取得任何成功。可能是什么问题?

我也希望通过社交媒体分享这个vCard,如whatsapp,email,messenger通过php。我怎样才能做到这一点?

我在网上搜索了很多解决方案,但找不到解决方案。请帮帮我。

我有两个用于生成vCard的文件,即vcard.php和vcardexp.inc.php,如下所示,

vcard.php

<?php

    include("vcardexp.inc.php"); 

    $test = new vcardexp;

    $test->setValue("firstName", "ماكس");
    $test->setValue("lastName", "Mustermann");
    $test->setValue("organisation", "Mustermann Holding GmbH");
    $test->setValue("tel_work", "01234/567890");
    $test->setValue("tel_home", "069/0123456");
    $test->setValue("tel_pref", "069/0123456");
    $test->setValue("url", "http://www.foo.bar");
    $test->setValue("email_internet", "max@foo.bar");
    $test->setValue("email_pref", "max@foo.bar");
    $test->setValue("street_home", "Musterstrasse 1");
    $test->setValue("postal_home", "12345");
    $test->setValue("city_home", "Musterstadt");
    $test->setValue("country_home", "Musterland");
    $test->copyPicture("test.jpg");

    $test->getCard();

?>

vcardexp.inc.php

<?php

    class vcardexp
    /* Bibliothek zur Genegierung von digitalen Visitenkarten */
    {

        //Deklarationen
        var $fields = array();

        var $allowed = array(
            "language",
            "firstName", "additionalName", "lastName", "title", "addon", "organisation", "note",
            "tel_work", "tel_home", "tel_cell", "tel_car", "tel_isdn", "tel_pref", "fax_work", "fax_home",
            "street_work", "city_work", "postal_work", "country_work", "street_home", "city_home", "postal_home", "country_home",
            "url", "email_internet", "email_pref", "picture"
        );



        function setValue($setting, $value)
        /* Wert eintragen */
        {

            //Ist die Einstellung in der Liste erlaubter Einstellungen?
            if(in_array($setting, $this->allowed))
            {
                //Ja, setze Einstellung und Wert
                $this->fields[$setting] = $value;
                return true;
            }
            else
            {
                //Nein
                return false;
            }

        }



        function copyPicture($path)
        /* Foto-Import */
        {
            //Ist die Datei vorhanden?
            if(is_file($path))
            {
                //Ja, beziehe die Bildgroesse
                $temp = getimagesize($path);

                //Ist das Bild nicht groesser als 185x185?
                if($temp[0] <= 185 && $temp[1] <= 185)
                {
                    //Ja, berechne base64-Code und setze
                    $this->fields["picture"] = base64_encode(file_get_contents ($path));
                    return true;
                }
                else
                {
                    //Nein, es ist zu gross
                    return false;
                }
            }
            else
            {
                //Nein, Datei ist nicht vorhanden
                return false;
            }
        }



        function setPicture($value)
        /* Bild direkt als BASE64-Code setzen, NOT RECOMMENDED */
        {
            $this->fields["picture"] = $value;
            return true;
        }



        function dump()
        /* Dump ausgeben */
        {

            echo "<pre>";
            print_r($this->fields);
            echo "</pre>";
            return true;

        }



        function getCard()
        /* Visitenkarte generieren */
        {

            //Header ausgeben
            header('Content-Type: text/x-vcard; charset=utf-8');
            $card  = "BEGIN:VCARD\n";
            $card .= "VERSION:2.1\n";

            //Sprache und Vor- und Nachname setzen
            if($this->fields["language"] == "") { $this->fields["language"] = "ar"; }
            $card .= "N;LANGUAGE=".$this->fields["language"].":".$this->fields["lastName"].";".$this->fields["firstName"]."\n";

            //Anzeigenamen setzen
            $card .= "FN:".$this->fields["firstName"]." ".$this->fields["lastName"]."\n";

            //Firma und Titel setzen, falls vorhanden
            if(isset($this->fields["organisation"]))
            {
                $card .= "ORG:".$this->fields["organisation"]."\n";
            }
            if(isset($this->fields["title"]))
            {
                $card .= "TITLE:".$this->fields["title"]."\n";
            }

            //zw  vn nicht gesetzt
            //zusatz nicht gesetzt
            //note nicht gesetzt
            //nur eine home tel
            //nur zwei mails
            //bug isset ==> array mit erlaubten feldern
            //Check fields

            //Telefon- und Faxnummern setzen

                if(isset($this->fields["tel_work"])) { $card .= "TEL;WORK;VOICE:".$this->fields["tel_work"]."\n"; } //Arbeit
                if(isset($this->fields["tel_home"])) { $card .= "TEL;HOME;VOICE:".$this->fields["tel_home"]."\n"; } //Privat
                if(isset($this->fields["tel_cell"])) { $card .= "TEL;CELL;VOICE:".$this->fields["tel_cell"]."\n"; }     //Handy
                if(isset($this->fields["tel_car"])) { $card .= "TEL;CAR;VOICE:".$this->fields["tel_car"]."\n"; }        //Autotelefon
                if(isset($this->fields["fax_work"])) { $card .= "TEL;WORK;FAX:".$this->fields["fax_work"]."\n"; }   //Fax-Arbeit
                if(isset($this->fields["fax_home"])) { $card .= "TEL;HOME;FAX:".$this->fields["fax_home"]."\n"; }   //Fax-Privat
                if(isset($this->fields["tel_home"])) { $card .= "TEL;HOME:".$this->fields["tel_home"]."\n"; }       //Privat, Kopie von obriger Angabe
                if(isset($this->fields["tel_isdn"])) { $card .= "TEL;ISDN:".$this->fields["tel_isdn"]."\n"; }           //ISDN
                if(isset($this->fields["tel_pref"])) { $card .= "TEL;PREF:".$this->fields["tel_pref"]."\n"; }           //Standard-Nummer



            //Adressen setzen

                //Arbeit
                if(isset($this->fields["street_work"]) && isset($this->fields["city_work"]) && isset($this->fields["postal_work"]) && isset($this->fields["country_work"]))
                {
                    $card .= "ADR;WORK;PREF:;;".$this->fields["street_work"].";".$this->fields["city_work"].";;".$this->fields["postal_work"].";".$this->fields["country_work"]."\n";
                    $card .= "LABEL;WORK;PREF;ENCODING=QUOTED-PRINTABLE:".$this->fields["street_work"]."=0D=0A=\n";
                    $card .= "=0D=0A=\n";
                    $card .= $this->fields["postal_work"]." ".$this->fields["city_work"]."\n";
                }

                //Privat
                if(isset($this->fields["street_home"]) && isset($this->fields["city_home"]) && isset($this->fields["postal_home"]) && isset($this->fields["country_home"]))
                {
                    $card .= "ADR;HOME;PREF:;;".$this->fields["street_home"].";".$this->fields["city_home"].";;".$this->fields["postal_home"].";".$this->fields["country_home"]."\n";
                    $card .= "LABEL;HOME;PREF;ENCODING=QUOTED-PRINTABLE:".$this->fields["street_home"]."=0D=0A=\n";
                    $card .= "=0D=0A=\n";
                    $card .= $this->fields["postal_home"]." ".$this->fields["city_home"]."\n";
                }



            //URL und E-Mails setzen

                if(isset($this->fields["url"])) { $card .= "URL;WORK:".$this->fields["url"]."\n"; }                     //Homepage setzen
                if(isset($this->fields["email_pref"])) { $card .= "EMAIL;PREF;INTERNET:".$this->fields["email_pref"]."\n"; }        //Standard-Mail
                if(isset($this->fields["email_internet"])) { $card .= "EMAIL;INTERNET:".$this->fields["email_internet"]."\n"; }     //Zusatz-Mail



            //Foto hinzufuegen, falls vorhanden
            if(isset($this->fields["picture"]))
            {
                $card .= "PHOTO;TYPE=JPEG;ENCODING=BASE64:\n";
                $card .= $this->fields["picture"];
                $card .= "\n\n\n";
            }

            //TODO: REV?

            //Ende setzen
            $card .= "END:VCARD";

            //Karte ausgeben und String loeschen
            echo $card;
            $card = "";

        }

    }

?>

3 个答案:

答案 0 :(得分:0)

如果您使用的是可添加的任何模板,请尝试将元标记添加到HTML代码中

<meta charset='UTF-8'>

在您的代码中,尝试在dump(),

中进行此更改
function dump()
    /* Dump ausgeben */
    {
        echo "<meta charset='UTF-8'>"; //HERE
        echo "<pre>";
        print_r($this->fields);
        echo "</pre>";
        return true;

    }

这应该有效,我能够以这种方式在本地工作。

答案 1 :(得分:0)

将CHARSET参数添加到相应的vCard属性可能会有所帮助。例如:

$card .= "FN;CHARSET=utf-8:" ...

或者,您可能需要明确告诉PHP以UTF-8输出字符串。 PHP只在输出HTML时更改其字符编码。

ini_set('default_charset', 'utf-8');

答案 2 :(得分:0)

我遇到了问题,IOS 8及更高版本的解决方案是:

在getCard()函数下的类文件REPLACE中:

public Result savemulti(String selected) throws PersistenceException {
    Form<Computer> computerForm = formFactory.form(Computer.class).bindFromRequest();
    if(computerForm.hasErrors()) {return badRequest(views.html.computers.editMulti.render(AuthorisedUser.findByEmail(request().username()), computerForm, selected));}
    java.util.Date dtcreate = new java.util.Date();
    String connectedEmail = ctx().session().get("email");
    AuthorisedUser singleUser = AuthorisedUser.findByEmail(connectedEmail);
    String[] ids = selected.split(";");
    Transaction txn = Ebean.beginTransaction();
    try{
        for (String temp : ids){  
            Computer savedComputer = Computer.find.byId(Long.parseLong(temp));
            if (savedComputer != null){
                Computer newComputerData = computerForm.get();
                savedComputer.company = newComputerData.company;
                savedComputer.discontinued = newComputerData.discontinued;
                savedComputer.introduced = newComputerData.introduced;
                savedComputer.name = newComputerData.name;
                savedComputer.status = newComputerData.status;          
                savedComputer.moddt = new java.sql.Timestamp(dtcreate.getTime());            
                savedComputer.modby = singleUser.userName;
                savedComputer.site = singleUser.site;                

                savedComputer.update();
                flash("success", "Computer [ " + computerForm.get().name + " ] has been updated");
                txn.commit();
            }
        }            
    } finally {
        txn.end();
    }        
    return GO_HOME;
}

对我来说效果很好。