I created a pass and can add it via app or web server in MAMP. What about sharing via email , how can I share it ?
Something like this should do the trick. Note that the MIME type needs to be application/vnd.apple.pkpass in order for the device to recognise it as a Passbook pass.
$pass = "pass.pkpass";
$path = "/path/to/pass/";
$from_name = "smallgirl";
$from_mail = "smallgirl#smallgirl.co.kr";
$reply_to = "smallgirl#smallgirl.co.kr";
$subject = "Your Passbook Pass.";
$message = "Hello,\r\nHere's your pass.";
email_pass($pass, $path, "recipient#mail.org",
$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;
}
}
By using Mail.app, now I can send a pass to others to add to passbook !
Related
I'm finding that I have the following Generic List, and I can see it has items in it, but when I try to run the code, it's not hitting inside the foreach. This is my code:
function SQLQueryWriteToFile([string]$SQLquery, [string]$extractFile)
{
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = "Server=blah;Database=blah;User ID=blah;Password=blah" #production #I have an error in this so it doesn't connect
$sqlConnection.Open()
if($sqlConnection.State -ne 'Open'){
$global:ErrorStrings.Add("Exception: $("Couldn't connect to DB with connection string given");; ") #this gets hit
}
###
$global:ErrorStrings = New-Object System.Collections.Generic.List[System.String] #System.Object]
$query = "Select blah"
$dir = "C:\blah"
SQLQueryWriteToFile $query $dir
$errorCodeAsString = ""
foreach ($item in $global:ErrorStrings.Members){
$errorCodeAsString += $item #this isn't hit
}
Any idea why it's not finding the error string in my list for the foreach loop, when I can see it's in there looking at $global:ErrorStrings? Based on this foreach list, I'm doing it correctly. I'm having trouble finding examples like what I'm doing. Thanks!
try this:
function SQLQueryWriteToFile([string]$SQLquery, [string]$extractFile)
{
[System.Data.SqlClient.SqlConnection] $sqlConnection=$null
[System.Data.SqlClient.SqlCommand] $command=$null
try
{
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = "Server=blah;Database=blah;User ID=blah;Password=blah"
$command = New-Object System.Data.SqlClient.SqlCommand
$command.Connection=$sqlConnection
$command.CommandText=$SQLquery
$sqlConnection.Open()
$command.ExecuteNonQuery()
}
catch
{
$global:ErrorStrings.Add($_.Exception.Message)
}
finally
{
if ($sqlConnection -ne $null)
{
$sqlConnection.Close()
$sqlConnection.Dispose()
}
if ($command -ne $null)
{
$command.Dispose()
}
}
}
$global:ErrorStrings = New-Object System.Collections.Generic.List[System.String]
$query = "Select blah"
$dir = "C:\blah"
$global:ErrorStrings.Clear()
SQLQueryWriteToFile $query $dir
$errorCodeAsString=""
for ($i = 0; $i -lt $global:ErrorStrings.Count; $i++)
{
$errorCodeAsString +=$global:ErrorStrings.Item($i)
}
$errorCodeAsString
I'm using the official AWS Golang SDK to integrate with SES but can't find any information about how to add some attachments (pdf file represented as []byte in code) to the email.
Could you help me?
The current email sending code looks like this:
sesEmailInput := &ses.SendEmailInput{
Destination: &ses.Destination{
ToAddresses: []*string{aws.String("To address")},
},
Message: &ses.Message{
Subject: &ses.Content{
Data: aws.String("Some text"),
},
Body: &ses.Body{
Html: &ses.Content{
Data: aws.String("Some Text"),
},
},
},
Source: aws.String("From address"),
ReplyToAddresses: []*string{
aws.String("From address"),
},
}
if _, err := s.sesSession.SendEmail(sesEmailInput); err != nil {
return err
}
To send attachments, use the SendRawEmail API instead of SendEmail. AWS documentation will generally refer to this as constructing a 'raw message' instead of explicitly calling out how to send attachments.
Example
From the AWS SDK for Go API Reference, linked below:
params := &ses.SendRawEmailInput{
RawMessage: &ses.RawMessage{ // Required
Data: []byte("PAYLOAD"), // Required
},
ConfigurationSetName: aws.String("ConfigurationSetName"),
Destinations: []*string{
aws.String("Address"), // Required
// More values...
},
FromArn: aws.String("AmazonResourceName"),
ReturnPathArn: aws.String("AmazonResourceName"),
Source: aws.String("Address"),
SourceArn: aws.String("AmazonResourceName"),
Tags: []*ses.MessageTag{
{ // Required
Name: aws.String("MessageTagName"), // Required
Value: aws.String("MessageTagValue"), // Required
},
// More values...
},
}
resp, err := svc.SendRawEmail(params)
Further Reading
Amazon SES API Reference - SendRawEmail
AWS SDK for Go API Reference - SendRawEmail
AWS SES Documentation - Sending Raw Email Using the Amazon SES API - This is a good primer for email standards and constructing raw messages (including a section about attachments).
after several wasted hours, things you should know about raw emails.
follow a structure like this:
boundary=boundary_name \n\n (create a boundary with boundary= and \n\n)
--boundary_name (start a boundary with --)
Header (add headers with Content-Type:)
(one blank line with \n)
html or text or file (add your content)
(one blank line with \n)
--boundary_name-- \n\n (close boundary with -- -- and \n\n)
Example with PHP code:
$boundary = md5(time());
$html = "<h1>E-mail Test</h1>";
$html .= "<img src=\"cid:{$attachment['filename']}\">"; // Content-ID
$text = "You need HTML enabled";
$raw = '';
$raw .= "From:{$from}\n";
$raw .= "To:{$to}\n";
$raw .= "Subject:{$subject}\n";
$raw .= "MIME-Version: 1.0\n";
$raw .= "Content-Type: multipart/mixed; boundary=\"{$boundary}\"\n\n";
$raw .= "--{$boundary}\n";
$raw .= "Content-Type: multipart/alternative; boundary=\"sub_{$boundary}\"\n\n";
$raw .= "--sub_{$boundary}\n";
$raw .= "Content-Type: text/plain; charset=\"UTF-8\"\n";
$raw .= "\n";
$raw .= "{$text}\n";
$raw .= "\n";
$raw .= "--sub_{$boundary}\n";
$raw .= "Content-Type: text/html; charset=\"UTF-8\"\n";
$raw .= "Content-Disposition: inline\n";
$raw .= "\n";
$raw .= "{$html}\n";
$raw .= "\n";
$raw .= "--sub_{$boundary}--\n\n";
foreach ($this->email->getFiles() as $attachment) {
$raw .= "--{$boundary}\n";
$raw .= "Content-Type:{$attachment['mimetype']}; name=\"{$attachment['filename']}\"\n"; // name
$raw .= "Content-Transfer-Encoding:base64\n";
$raw .= "Content-Disposition:attachment;filename=\"{$attachment['filename']}\"\n"; // filename
#$raw .= "Content-Disposition:inline;name={$file_name}\n";
$raw .= "Content-ID:<{$attachment['filename']}>\n";
$raw .= "\n";
$raw .= base64_encode($attachment['content']) . "\n";
$raw .= "\n";
}
$raw .= "--{$boundary}--\n\n";
Final raw Message example:
From:Name From<name#from.com>
To:email#to.com,second#to.com
Subject:Your subject
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="b4f53df7c26ae6945f29c42d5c2bb55f"
--b4f53df7c26ae6945f29c42d5c2bb55f
Content-Type: multipart/alternative; boundary="sub_b4f53df7c26ae6945f29c42d5c2bb55f"
--sub_b4f53df7c26ae6945f29c42d5c2bb55f
Content-Type: text/plain; charset="UTF-8"
You need HTML enabled
--sub_b4f53df7c26ae6945f29c42d5c2bb55f
Content-Type: text/html; charset="UTF-8"
Content-Disposition: inline
<h1>E-mail Test</h1>
<img src="cid:qrcode.png"> // <-- from Header Content-ID:<name>
--sub_b4f53df7c26ae6945f29c42d5c2bb55f--
--b4f53df7c26ae6945f29c42d5c2bb55f
Content-Type:image/png; name="qrcode.png"
Content-Transfer-Encoding:base64
Content-Disposition:attachment;filename="qrcode.png"
Content-ID:<qrcode.png> // you can use <img src="cid:qrcode.png"> in html
iVBORw0K== // base64encoded file contents
--b4f53df7c26ae6945f29c42d5c2bb55f
Content-Type:image/png; name="another_file.png"
Content-Transfer-Encoding:base64
Content-Disposition:attachment;filename="another_file.png"
Content-ID:<another_file.png>
iVBORw0KGg== // base64encoded file contents
--b4f53df7c26ae6945f29c42d5c2bb55f--
Don't forget, after Headers, one blank lines before and after content
For PHP AWS SDK
try {
$client = new SesClient($options);
$result = $client->sendRawEmail([
'RawMessage' => [
'Data' => $raw
],
]);
echo $result['MessageId'];
}
catch (AwsException $e) {
echo $e->getAwsErrorMessage();
return false;
}
SES raw messages must be base64-encoded. So, you'll need to get the file content as buffer and encode it as base64 string attachment. Also, you don't need to create a new buffer for raw message data since it already accepts a string data type.
OPTIONAL: You can also omit the Destinations parameter since you're already providing the To field in the raw message data. (You can also provide the Cc and Bcc fields as well)
You could try this for example:
const sendAttachmentEmail = async () => {
// Yo can use by this way
const DATA = await workbook.writeToBuffer(); // This workbook is excel generated
// Or this way
const DATA = fs.readFileSync("files/demo-invoice.xlsx"); // This is excel file in files folder
const SOURCE_EMAIL = "xyz#gmail.com";
const TO_EMAIL = "abc#gmail.com";
let ses_mail = "From: 'AWS SES Attchament Configuration' <" + SOURCE_EMAIL + ">\n";
ses_mail += "To: " + TO_EMAIL + "\n";
ses_mail += "Subject: AWS SES Attachment Example\n";
ses_mail += "MIME-Version: 1.0\n";
ses_mail += "Content-Type: multipart/mixed; boundary=\"NextPart\"\n\n";
ses_mail += "--NextPart\n";
ses_mail += "Content-Type: text/html\n\n";
ses_mail += "This is the body of the email.\n\n";
ses_mail += "--NextPart\n";
ses_mail += "Content-Type: application/octet-stream; name=\"demo-invoice.xlsx\"\n";
ses_mail += "Content-Transfer-Encoding: base64\n";
ses_mail += "Content-Disposition: attachment\n\n";
ses_mail += data.toString("base64").replace(/([^\0]{76})/g, "$1\n") + "\n\n";
ses_mail += "--NextPart--";
const params = {
RawMessage: {
Data: ses_mail
},
Source: "'AWS SES Attchament Configuration' <" + SOURCE_EMAIL + ">'"
};
return new Promise((resolve, reject) => {
ses.sendRawEmail(params, (err) => {
if (err) {
return reject(err);
}
return resolve();
});
});
};
NOTE: The /([^\0]{76})/ regular expression replacement breaks your long lines to make sure that mail servers do not complain about message lines being too long when there is an encoded attachment, which might result in a transient bounce.
I have this script for making subdomain and I want to placed it in the opencart contoller. How to do that and how to make it work with the insert function?
$cpanel_user = 'root';
$cpanel_pass = 'password';
$cpanel_skin = 'x2';
$cpanel_host = 'yourdomain.com';
$subdomain = 'mysubdomain';
$dir = 'public_html/mysubdomain';
$sock = fsockopen($cpanel_host,2082);
if(!$sock) {
print('Socket error');
exit();
}
$pass = base64_encode("$cpanel_user:$cpanel_pass");
$in = "GET /frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$cpanel_host&domain=$subdomain&dir=$dir\r\n";
$in .= "HTTP/1.0\r\n";
$in .= "Host:$cpanel_host\r\n";
$in .= "Authorization: Basic $pass\r\n";
$in .= "\r\n";
fputs($sock, $in);
while (!feof($sock)) {
$result .= fgets ($sock,128);
}
fclose($sock);
I'm using wp_link_pages() to display pagination, Which looks like:
1
2
3
4
Since this just returns a formatted html string like the above, I find it hard to wrap the current page number in a span to look something like:
<span class="current">1</span>
2
3
4
How to wrap a number surrounded with spaces (sometimes nothing or even <a> tags) in a span tag?
Put this code in functions.php
function custom_wp_link_pages( $args = '' ) {
$defaults = array(
'before' => '<p id="post-pagination">' . __( 'Pages:' ),
'after' => '</p>',`enter code here`
'text_before' => '',
'text_after' => '',
'next_or_number' => 'number',
'nextpagelink' => __( 'Next page' ),
'previouspagelink' => __( 'Previous page' ),
'pagelink' => '%',
'echo' => 1
);
$r = wp_parse_args( $args, $defaults );
$r = apply_filters( 'wp_link_pages_args', $r );
extract( $r, EXTR_SKIP );
global $page, $numpages, $multipage, $more, $pagenow;
$output = '';
if ( $multipage ) {
if ( 'number' == $next_or_number ) {
$output .= $before;
for ( $i = 1; $i < ( $numpages + 1 ); $i = $i + 1 ) {
$j = str_replace( '%', $i, $pagelink );
$output .= ' ';
if ( $i != $page || ( ( ! $more ) && ( $page == 1 ) ) )
$output .= _wp_link_page( $i );
else
$output .= '<span class="current-post-page">';
$output .= $text_before . $j . $text_after;
if ( $i != $page || ( ( ! $more ) && ( $page == 1 ) ) )
$output .= '</a>';
else
$output .= '</span>';
}
$output .= $after;
} else {
if ( $more ) {
$output .= $before;
$i = $page - 1;
if ( $i && $more ) {
$output .= _wp_link_page( $i );
$output .= $text_before . $previouspagelink . $text_after . '</a>';
}
$i = $page + 1;
if ( $i <= $numpages && $more ) {
$output .= _wp_link_page( $i );
$output .= $text_before . $nextpagelink . $text_after . '</a>';
}
$output .= $after;
}
}
}
if ( $echo )
echo $output;
return $output;
}
And call with custom_wp_link_pages()
Source: http://bavotasan.com/2012/a-better-wp_link_pages-for-wordpress/
Why regex as tag ?
You need to use something like:
Page-links in Paragraph Tags
<?php wp_link_pages('before=<p>&after=</p>&next_or_number=number&pagelink=page %'); ?>
Displays page-links wrapped in paragraph tags.
Page-links in DIV
<?php wp_link_pages('before=<div id="page-links">&after=</div>'); ?>
Displays page-links in DIV for CSS reference as <div id="page-links">.
Docs reference : http://codex.wordpress.org/Function_Reference/wp_link_pages
In my app. i get user's feed and user's news ticker. With first i have no questions, but with the second i have some troubles. How a can access to the ticker using php?
From my experience the ticker is just a shortened version of a users news feed using "story"
Here is a sample batch request "with only 1 request" i use to display ticker info from a users news feed.
user / home https://developers.facebook.com/docs/reference/api/user/#home
filtering results based on user lists https://developers.facebook.com/docs/reference/fql/stream_filter/
API Request:
<?php
$Ticker = $facebook->api('/me/home?fields=id,story%26'.$access_token.'');
echo '<pre>';
print_r($Ticker);
echo '</pre>';
?>
Batch API Request:
<?php
$Ticker = '/me/home?fields=id,story%26'.$access_token.'';
$queries = array(
array('method' => 'GET', 'relative_url' => ''.$Ticker.'')
);
$batchResponse = $facebook->api('?batch='.json_encode($queries), 'POST');
$MEticker = json_decode($batchResponse[0]['body'], true);
echo '<pre>';
print_r($MEticker);
echo '</pre>';
?>
Thank you very much! I almost understood! :)
Another way to get ticker:
<?php
$res = $app->facebook->get_friends_news('me',$access_token);
print_r($res);
print "Ticker:"."\r\n";
foreach ($res['data'] as $value){
if (isset($value['story'])){
echo $value['story']."\r\n";
}
}
?>
where
<?php
function get_friends_news($user_id ='me',$token)<br/>
{
$url = $this->url_base_graph.$user_id.'/home?access_token='.$token;
$res = json_decode($this->httpQuery($url),true);
return $res;
}
?>
And:
<?php
function httpQuery($url, $method = 'GET', $post_data = array(), $CONNECTTIMEOUT = 30) {
// type of query
if ($method == 'POST')
$method = 1;
elseif ($method == 'GET')
$method = 0;
if ($this->access_token != false)
$url = $url . 'access_token=' . $this->access_token;
//echo $url;
//traverse array and prepare data for posting (key1=value1)
if (count($post_data)) {
foreach ($post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode('&', $post_items);
} else {
$post_string = '';
}
// echo $url;
//create cURL connection
$curl_connection = curl_init($url);
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, $CONNECTTIMEOUT);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_URL, $url);
curl_setopt($curl_connection, CURLOPT_POST, $method);
//set data to be posted
if ($post_string != '') {
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
}
//perform our request
$result = curl_exec($curl_connection);
//close the connection
curl_close($curl_connection);
return $result;
}?>