2013-03-28 37 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