AWS SES SDK send email with attachments - amazon-web-services

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.

Related

How to send push to specific member using SNS topic?

I am using AWS SNS to send a push notification, right now i am using publish method of aws-php-sdk to send push specific device. My requirement is sent push to thousands of members within 30 seconds. When i used publish method it takes 5min to send 1000 users.
I have read about topic it sends multiple members at once, but my scenario is i want to send push to specific users, not all topic users.
For example, i register 10,000 members in one topic, but from this 10,000 some time i am sending 9000, sometimes 1000 members.
So anyone has an idea how to send push using topic but specific members only.
I also think another case, every time i create new topic and register member to this topic and then send a message to him and then delete topic, but here every time when register member it is also taking time. So if you have an idea to register multiple members at once then it will also be helpful for me.
Below is my current code to send push.
$arn = "user arn";
$sns = new Aws\Sns\SnsClient(array(
'version' => 'latest',
'key' => my_aws_key,
'secret' => aws_secret,
'region' => region,
'profile' => profile_name,
'debug' => false,
'http' => array('verify' => false)
));
$appArn = "application arn";
$sns->publish(array('Message' => '{ "GCM": "{\"data\": { \"message\": \" This is my message \"} }"}',
'MessageStructure' => 'json',
'TargetArn' => $arn
));
I would recommend to use publishAsync() method.
$userArnCollection = array(
'arn:XXX',
'arn:YYY',
'arn:ZZZ',
);
$sns = new Aws\Sns\SnsClient(array(
'version' => 'latest',
'key' => my_aws_key,
'secret' => aws_secret,
'region' => region,
'profile' => profile_name,
'debug' => false,
'http' => array('verify' => false)
));
foreach ($userArnCollection as $userArn) {
$sns->publishAsync(array(
'Message' => '{ "GCM": "{\"data\": { \"message\": \" This is my message \"} }"}',
'MessageStructure' => 'json',
'TargetArn' => $userArn
));
}
EDIT
Example with promise handling
$userArnCollection = array(
'arn:XXX',
'arn:YYY',
'arn:ZZZ',
);
$sns = new Aws\Sns\SnsClient(array(
'version' => 'latest',
'key' => my_aws_key,
'secret' => aws_secret,
'region' => region,
'profile' => profile_name,
'debug' => false,
'http' => array('verify' => false)
));
$promises = array();
foreach ($userArnCollection as $userArn) {
$promises[] = $sns->publishAsync(array(
'Message' => '{ "GCM": "{\"data\": { \"message\": \" This is my message \"} }"}',
'MessageStructure' => 'json',
'TargetArn' => $userArn
));
}
$results = \GuzzleHttp\Promise\unwrap($promises);
After trying many solutions i am able to send thousands of notification within one minute, here i am showing code how i do it, I have done with php multicurl functionality, so i execute multiple parallel processes and all process send notification simultaneously.
Define multi curl and prepare URL to send notification
Suppose i have 5,000 members and i have array of it's token and other member details $device_type_ids_arr
I part of all member to 500 bunch, so each time curl execute it sends notification to 500 members
$_datas = array_chunk($device_type_ids_arr, 500);
/*initialise multi curl*/
$mh = curl_multi_init();
$handles = array();
/* Perform loop for each 500 members batch */
foreach ($_datas as $batchPart) {
$ch = curl_init();
$postData['devices'] = $batchPart;
$postData['push_content'] = $push_content;
$data_string = json_encode($postData);
curl_setopt($ch, CURLOPT_URL, base_url() . "EmailPipe/sendNotification/"); //your URL to call amazon service (Explain below)
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_USERAGENT, 'User-Agent: curl/7.39.0');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length:' . strlen($data_string))
);
curl_multi_add_handle($mh, $ch);
$handles[] = $ch;
}
// execute requests and poll periodically until all have completed
$isRunning = null;
do {
curl_multi_exec($mh, $isRunning);
} while ($isRunning > 0);
/* Once all execution are complete remove curl handler */
foreach ($handles as $ch) {
curl_multi_remove_handle($mh, $ch);
}
/* Close multi curl */
curl_multi_close($mh);
Function which is received curl request and send notification
function sendCurlSignal() {
require_once APPPATH . 'libraries/aws-sdk/aws-autoloader.php';
$pipeArr = json_decode(file_get_contents('php://input'), true);
$push_content = $pipeArr["push_content"];
$device_id_arr = $pipeArr["devices"];
$sns = new Aws\Sns\SnsClient(array(
'version' => 'latest',
'key' => "Amazon key",
'secret' => "Amazon secret",
'region' => "region like eu-west-1",
'profile' => "Amazon account user",
'debug' => false,
'http' => array('verify' => false)
));
$appArn = "SNS application arn";
$promises = $results = $retArr = array();
foreach ($device_id_arr as $key => $device_detail) {
$arn = $device_detail['arn']; /* SNS ARN of each device */
$token = $device_detail['token_id']; /* Registered token */
$userid = $device_detail['member_id'];
/* If you don't have arn then add arn for specific token in amazon */
if (empty($arn)) {
try {
$updatedArn = $sns->createPlatformEndpoint(array('PlatformApplicationArn' => $appArn, 'Token' => $token));
$arn = $newArn = isset($updatedArn['EndpointArn']) ? $updatedArn['EndpointArn'] : "";
//update member detail with new arn
if ($newArn != "" && $userid != "" && $token != "") {
/* You can update arn into database for this member */
}
} catch (Exception $e) {
/* Get error if any */
$errorMsg = $e->getMessage();
$newFile = fopen("error_arn_fail.txt", "a+");
fwrite($newFile, "Member Id:" . $userid . "\r\nToken:" . $token . "\r\n" . $errorMsg . "\r\n");
fclose($newFile);
}
}
if (!empty($arn)) {
try {
$promises[$userid] = $sns->publishAsync(array(
'Message' => '{ "GCM": "{\"data\": { \"message\": \"' . $push_content . '\" } }"}',
'MessageStructure' => 'json',
'TargetArn' => $arn
));
$promises[$userid]->arn = $arn;
$promises[$userid]->token = $token;
} catch (Exception $e) {
$errorMsg = $e->getMessage();
$newFile = fopen("error_async_fail_signal.txt", "a+");
fwrite($newFile, $errorMsg . "\r\n");
fclose($newFile);
}
}
}
/* Broadcast push notification */
$results = \GuzzleHttp\Promise\settle($promises)->wait(TRUE);
/* if you want to get result of broadcast and sent message id then do following */
foreach ($results as $key => $value) {
if (isset($value['reason'])) {
/* Reason come in case of fail */
$message = $value['reason']->getMessage();
$token = (isset($promises[$key]->token)) ? $promises[$key]->token : "";
$arn = (isset($promises[$key]->arn)) ? $promises[$key]->arn : "";
if (empty($arn) || empty($token) || empty($key)) {
$newFile = fopen("error_empty_detail_result.txt", "a+");
fwrite($newFile, "Member Id:" . $key . "\r\nArn:" . $arn . "\r\nToken:" . $token . "\r\n");
fclose($newFile);
}
/* Handle error */
if (strpos($message, "Endpoint is disabled") !== false && $token != "" && $arn != "") {
try {
$res = $sns->setEndpointAttributes(array(
'Attributes' => array("Token" => $token, "Enabled" => "true"),
'EndpointArn' => $arn
));
} catch (Exception $e) {
$errorMsg = $e->getMessage();
$newFile = fopen("error_endpoint_disable.txt", "a+");
fwrite($newFile, "Member Id:" . $key . "\r\nArn:" . $arn . "\r\nToken:" . $token . "\r\n" . $errorMsg . "\r\n");
fclose($newFile);
}
}
if (strpos($message, "No endpoint found for the target arn specified") !== false && $token != "") {
try {
$updatedArn = $sns->createPlatformEndpoint(array('PlatformApplicationArn' => $appArn, 'Token' => $token));
$arn = $newArn = isset($updatedArn['EndpointArn']) ? $updatedArn['EndpointArn'] : "";
//update member detail with new arn
if ($newArn != "" && !empty($key) && $token != "") {
/* You can update arn into database for this member */
}
} catch (Exception $e) {
$errorMsg = $e->getMessage();
$newFile = fopen("error_arn_fail.txt", "a+");
fwrite($newFile, "Member Id:" . $key . "\r\nToken:" . $token . "\r\n" . $errorMsg . "\r\n");
fclose($newFile);
}
}
/* After handle error resed notification to this users */
if (!empty($arn)) {
try {
$publishRes = $sns->publish(array(
'Message' => '{ "GCM": "{\"data\": { \"message\": \"' . $push_content . '\" } }"}',
'MessageStructure' => 'json',
'TargetArn' => $arn
));
$retArr[$key] = $publishRes->get("MessageId");
} catch (Exception $e) {
$errorMsg = $e->getMessage();
$newFile = fopen("error_push_not_sent.txt", "a+");
fwrite($newFile, "Member Id:" . $key . "\r\nARN:" . $arn . "\r\nToken:" . $token . "\r\n" . $errorMsg . "\r\n");
fclose($newFile);
}
}
} else {
$retArr[$key] = $results[$key]['value']->get("MessageId");
}
}
/* All member data get into one array to perform database operation */
if (isset($retArr) && !empty($retArr)) {
/* in $retArr you get each member amazon message id */
}
}

How to make controller opencart function

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);

How to share pass via email

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 !

Vtiger Webform issue

I am trying to store data in vtiger leads module. i can send variable via file_get_contents()
but its not working . here is my code
$moduleName = $_POST['moduleName'];
$company = $_POST['company'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$website = $_POST['website'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$city = $_POST['city'];
$state = $_POST['state'];
$code = $_POST['code'];
$post = http_build_query(array(
"firstname" => "$firstname",
"lastname" => "$lastname",
"website"=>"$website",
"phone"=>"$phone",
"email"=>"$email",
"city"=>"$city",
"state"=>"$state",
"code"=>"$code",
"moduleName" => "$moduleName",
"company " => "$company",
));
$context = stream_context_create(array("http"=>array(
"method" => "POST",
"header" => "Content-Type: application/x-www-form-urlencoded\r\n" .
"Content-Length: ". strlen($post) . "\r\n",
"content" => $post,
)));
$page = file_get_contents("http://vtiger.com/modules/Webforms/post.php", false, $context);
Please help me.
Use web forms correctly, in vtiger 5.4 you can create webforms ealsily with its interface. oru user vtiger webservices to create,edit,delte data

Could you explain me how i get news tickers from facebook into my app?

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;
}?>