Formatting VCard in PHP

后端 未结 3 1217
野性不改
野性不改 2021-01-03 17:30

I\'m trying to generate a VCard via PHP, and them email it out to the user. I wrote an initial script with hard-coded data, but the end-result will fill in the VCard from M

3条回答
  •  有刺的猬
    2021-01-03 17:43

    I had to get vcards working in android and iphone recently. I used the following function which is a modified version of the one listed above. This will send vcards that both gmail and mail on the iphone will be able to open. They work in Thunderbird as well.

    function mail_attachment($filename, $content, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
        $fileatt_type = "text/x-vcard";
    
        $headers = "FROM: ".$from_mail;
    
        $data = $content;
    
        $semi_rand = md5(time());
        $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    
        $headers .= "\nMIME-Version: 1.0\n" .
        "Content-Type: multipart/mixed;\n" .
        " boundary=\"{$mime_boundary}\"";
    
        $message = "This is a multi-part message in MIME format.\n\n" .
        "--{$mime_boundary}\n" .
        "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
        "Content-Transfer-Encoding: 7bit\n\n" .
        $message . "\n\n";
        $message .= "--{$mime_boundary}\n" .
        "Content-Type: {$fileatt_type};\n" .
        " name=\"{$filename}\"\n" .
        "Content-Transfer-Encoding: 8bit\n" .
        "Content-Disposition: attachment;\n" .
        " filename=\"{$filename}\"\n\n" .
        $data . "\n\n" .
        "--{$mime_boundary}--\n";
        //echo "sending message";
        mail($mailto, $subject, $message, $headers);
    }
    

提交回复
热议问题