2013-03-28 59 views

回答

0

通過使用Mail.app,現在我可以送一通給別人添加到存摺!

0

像這樣的東西應該做的伎倆。請注意,MIME類型需要爲application/vnd.apple.pkpass,以便設備將其識別爲Passbook通行證。

$pass = "pass.pkpass"; 
$path = "/path/to/pass/"; 
$from_name = "smallgirl"; 
$from_mail = "[email protected]"; 
$reply_to = "[email protected]"; 
$subject = "Your Passbook Pass."; 
$message = "Hello,\r\nHere's your pass."; 

email_pass($pass, $path, "[email protected]", 
      $from_mail, $from_name, $reply_to, $subject, $message); 

function email_pass($pass, $path, $mail_to, $from_mail, $from_name, $reply_to, $subject, $message) { 
    $content = chunk_split(base64_encode(file_get_contents($path.$pass))); 
    $uid = md5(uniqid(time())); 
    $name = basename($pass); 
    $header = "From: ".$from_name." <".$from_mail.">\r\n"; 
    $header .= "Reply-To: ".$reply_to."\r\n"; 
    $header .= "MIME-Version: 1.0\r\n"; 
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; 
    $header .= "This is a multi-part message in MIME format.\r\n"; 
    $header .= "--".$uid."\r\n"; 
    $header .= "Content-type:text/plain; charset=utf-8\r\n"; 
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; 
    $header .= $message."\r\n\r\n"; 
    $header .= "--".$uid."\r\n"; 
    $header .= "Content-Type: application/vnd.apple.pkpass; name=\"".$pass."\"\r\n"; // use different content types here 
    $header .= "Content-Transfer-Encoding: base64\r\n"; 
    $header .= "Content-Disposition: attachment; filename=\"".$pass."\"\r\n\r\n"; 
    $header .= $content."\r\n\r\n"; 
    $header .= "--".$uid."--"; 
    if (mail($mail_to, $subject, "", $header)) { 
     return true; 
    } else { 
     return false; 
    } 
} 
+0

我不是很懂!我是否必須使用上面的代碼創建一個php文件,然後通過電子郵件分享它? – malinchhan 2013-03-28 07:58:42

+0

此代碼將允許您的服務器通過電子郵件發送文件 - 添加它的最佳位置應該在您用來創建通行證的php文件中。如果您只是想手動發送文件,那麼只需將.pkpass文件附加到任何電子郵件,就像您使用任何其他文件一樣! – PassKit 2013-03-28 08:06:03

+0

如果我附加.pkpass,它只是一個文件,而不是通過,用戶也不能添加到存摺! – malinchhan 2013-03-28 08:09:26