I'm writing a class wrapper for LinkedIn API and I'm using Zend Framework 1.11.2. Here is a snippet I have:
$config = Pb_Portal::getInstance()->getConfig('linkedin.ini');
$body = '<?xml version="1.0" encoding="UTF-8"?>';
$body .= '<share>';
$body .= '<comment>83% of employers will use social media to hire: 78% LinkedIn, 55% Facebook, 45% Twitter [SF Biz Times] http://bit.ly/cCpeOD</comment>';
$body .= '<content>';
$body .= '<title>Survey: Social networks top hiring tool - San Francisco Business Times</title>';
$body .= '<submitted-url>http://sanfrancisco.bizjournals.com/sanfrancisco/stories/2010/06/28/daily34.html</submitted-url>';
$body .= '<submitted-image-url>http://images.bizjournals.com/travel/cityscapes/thumbs/sm_sanfrancisco.jpg</submitted-image-url>';
$body .= '</content>';
$body .= '<visibility>';
$body .= '<code>anyone</code>';
$body .= '</visibility>';
$body .= '</share>';
$client = Zend_Oauth::getHttpClient();
$client->setUri('http://api.linkedin.com/v1/people/~/shares');
$client->setMethod(Zend_Http_Client::POST);
$client->setRawData($body,'text/xml');
$client->setHeaders('Content-Type', 'text/xml');
$client->setParameterPost('oauth_consumer_key', $config->appKey);
$client->setParameterPost('oauth_nonce', $config->appSecretKey);
$client->setParameterPost('oauth_token', $acc->getToken());
$client->setParameterPost('oauth_timestamp', time());
$client->setParameterPost('oauth_signature_method', 'HMAC-SHA1');
$client->setParameterPost('oauth_version', '1.0');
$response = $client->request();
$xml = #simplexml_load_string($response->getBody());
And I have this response:
SimpleXMLElement Object
(
[status] => 401
[timestamp] => 1299581073233
[error-code] => 0
[message] => Unknown authentication scheme
)
Can somebody help me? Where I go wrong?
I had a similar problem (although I am just retrieving user info). This link helped a great deal. Instead of constructing the params as get variables, you allow the token to construct the http client from your options.
http://www.contentwithstyle.co.uk/content/linkedin-and-zendoauth/
You may need to change the way you are writing class wrapper.
You can take idea from this post and accepted answer there!!
Linkedin: How to make api calls using access token?
best of luck
Related
I'm sending a calendar invite via email but I want it automatically be accepted.
Is there something I can change in my code? My code looks like this:
function sendIcalEmail ($firstname, $lastname, $email, $meeting_date, $meeting_name, $meeting_duration) {
$from_name = “My Name”;
$from_address = “myname#mydomain.com”;
$subject = “Meeting Booking”; //Doubles as email subject and meeting subject in calendar
$meeting_description = “Here is a brief description of my meeting\n\n”;
$meeting_location = “My Office”; //Where will your meeting take place
//Convert MYSQL datetime and construct iCal start, end and issue dates
$meetingstamp = strtotime($meeting_date . ” UTC”);
$dtstart= gmdate(”Ymd\THis\Z”,$meetingstamp);
$dtend= gmdate(”Ymd\THis\Z”,$meetingstamp+$meeting_duration);
$todaystamp = gmdate(”Ymd\THis\Z”);
//Create unique identifier
$cal_uid = date(’Ymd’).’T’.date(’His’).”-”.rand().”#mydomain.com”;
//Create Mime Boundry
$mime_boundary = “—-Meeting Booking—-”.md5(time());
//Create Email Headers
$headers = “From: “.$from_name.” <”.$from_address.”>\n”;
$headers .= “Reply-To: “.$from_name.” <”.$from_address.”>\n”;
$headers .= “MIME-Version: 1.0\n”;
$headers .= “Content-Type: multipart/alternative; boundary=\”$mime_boundary\”\n”;
$headers .= “Content-class: urn:content-classes:calendarmessage\n”;
//Create Email Body (HTML)
$message .= “–$mime_boundary\n”;
$message .= “Content-Type: text/html; charset=UTF-8\n”;
$message .= “Content-Transfer-Encoding: 8bit\n\n”;
$message .= “<html>\n”;
$message .= “<body>\n”;
$message .= ‘<p>Dear ‘.$firstname.’ ‘.$lastname.’,</p>’;
$message .= ‘<p>Here is my HTML Email / Used for Meeting Description</p>’;
$message .= “</body>\n”;
$message .= “</html>\n”;
$message .= “–$mime_boundary\n”;
//Create ICAL Content (Google rfc 2445 for details and examples of usage, beware of adding tabs)
$ical = ‘BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
ORGANIZER:MAILTO:’.$from_address.’
DTSTART:’.$dtstart.’
DTEND:’.$dtend.’
LOCATION:’.$meeting_location.’
TRANSP:OPAQUE
SEQUENCE:0
UID:’.$cal_uid.’
DTSTAMP:’.$todaystamp.’
DESCRIPTION:’.$meeting_description.’
SUMMARY:’.$subject.’
PRIORITY:5
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR’;
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST;charset=utf-8\n';
$message .= 'Content-Transfer-Encoding: 8bit\n\n';
$message .= $ical;
//SEND MAIL
$mail_sent = #mail( $email, $subject, $message, $headers );
if($mail_sent) {
return true;
} else {
return false;
}
}
Imho it is not or should not be possible to post an invite that automatically will be accepted. Instead you should inform your users that they can they can change their settings in Outlook to automatically accept (certain) invites.
Btw thanks for your snippet. Just what I needed.
Hi for calendar auto acceptance you should add the given lines in your code to create ics file.
ATTENDEE;PARTSTAT=ACCEPTED;CN= ExampleName1 c;EMAIL=example1#mail.com:MAILTO:example1#mail.com
ATTENDEE;PARTSTAT=ACCEPTED;CN= ExampleName2 c;EMAIL=example2#mail.comMAILTO:example2#mail.com
Recently i came across -- as a header of mail() function in php. I tried to google it out but didn't found any result so i am posting this question. While trying to edit my code i found that the id after these two -- should be unique.My php script to send email with attachement.
<?php
$file = "http://wpbrisk.com/download/email/email/doc1.pdf"; // Specify the Url of the attachment here
$filename = "doc1.pdf"; // Specify the name of the file here
$to="hudixt#gmail.com"; // Enter the mail to which you want to sent the attachement
$your_name = "Hudixt"; // Your name
$from_mail = "info#wpbrisk.com"; // Your email
$subject = "This is a mail with attachment."; // Subject
$message = "<div id='hello'>World</div>"; // message
// Get the content of the file
$content = file_get_contents($file);
$content = base64_encode($content);
$uid = md5(uniqid(time()));
$header = "From: ".$from_name." <".$from_mail.">\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/html; charset=iso-8859-1' . "\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
mail($mailto, $subject, "", $header);
?>
Can you please tell me what this -- means in header and why it should be unique.
These "--ID--" lines are MIME part boundaries (see https://en.wikipedia.org/wiki/MIME). They are described in https://www.rfc-editor.org/rfc/rfc2046. They are used to separate different parts of a message.
According to RFC#2046 those only must be unique "enough". If you want to encapsulate an email into another one, the boundaries must not infer with each other, i.e. they have to be distinct. So it's a good idea to make them as unique "as possible and needed":
This implies that it is crucial that the composing agent be able
to choose and specify a unique boundary parameter value that does
not contain the boundary parameter value of an enclosing multipart
as a prefix.
(https://www.rfc-editor.org/rfc/rfc2046#section-5.1)
Seems like a MIME boundary to me...
Basically, when you have multiple types of content in an e-mail message, the different parts are separated using an ID. Each part is then preceded by '--' followed by the boundary. From the RFC:
Thus, a typical multipart Content-Type header field might look like this:
Content-Type: multipart/mixed;
boundary=gc0p4Jq0M2Yt08jU534c0p
This indicates that the entity consists of several parts, each itself with a structure that is syntactically identical to an RFC 822 message, except that the header area might be completely empty, and that the parts are each preceded by the line
--gc0p4Jq0M2Yt08jU534c0p
See http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html for more info.
To answer your last question, when you have an e-mail with text and attachment, the whole message will have Content-Type: multipart/mixed, the text will be text/plain, the attachment (suppose a word file) will be application/msword. Each new content-type part will be separated by '--' . $boundary. The boundary is chosen to be unique and different from the other message parts so that it doesn't appear inside either of them - when the application interpreting the e-mail contents finds $boundary it must be safe to assume that's an intended boundary and not just a fluke inside the message.
Hope that helps!
I am creating a page that sends the response from contact form within mail but reply-to is not working (the variable i am using is having value, but is not added within headers)
here's my code:
<?php
//$uname=$_REQUEST['uname'];
if(isset($_REQUEST['name']))
{
$name=$_REQUEST['name'];
}
if(isset($_REQUEST['email']))
{
$email=$_REQUEST['email'];
}
if(isset($_REQUEST['phone']))
{
$phone=$_REQUEST['phone'];
}
if(isset($_REQUEST['message']))
{
$message=$_REQUEST['message'];
}
// TESTING IF VARIABLES HAVE VALUES
echo "$name $email $phone $message";
// RESULT: TRUE TILL HERE
if($name=="" || $email=="" || $phone=="" || $message=="")
{
header("location:../?inst=invalid");
}
else
{
// ---------------- SEND MAIL FORM ----------------
// send e-mail to ...
$to="mail#example.com";
// Your subject
$subject="$name Contacted you via Contact Form";
// From
$headers = "From: ME <no-reply#example.com>\r\n";
$headers .= 'Reply-To:' . $email . "\r\n";
$headers .= "Return-Path: info#example.com\r\n";
$headers .= "X-Mailer: PHP\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
print $message;
// send email
$sentmail = mail($to,$subject,$message,$headers);
//$sentmail = mail($to1,$subject,$message,$header);
}
// if your email succesfully sent
if($sentmail){
echo "Mail Sent.";
}
else {
header("location:../landing/?status=verification-pending");
}
?>
Now when i checked headers in my gmail, the value for $email doesn't appear in header information, Also no message is received. All I get is a blank message or may be $message is not printing anything like the same case i am facing with reply-to.
please help me a little with this. Thanks in advance.
Check that you have php warnings and notices enabled. When you are echoing out $name, $email, etc you are doing a redirect using headers after that. If your php notices etc aren't turned on, your header redirect will fail due to having already echoed something, and you won't know that you had invalid input. This is part of the reason you shouldn't echo things out during logic, but should store and out put values later.
Actually there was a little mistake with the above code. I mistakenly added = instead of == while comparison.
This line:
if($name=="" || $email="" || $phone="" || $message="")
Should read as:
if($name=="" || $email=="" || $phone=="" || $message=="")
Since = is for equation and not a condition for comparison ==
Fixed it in the Question
I have below code(httpbody for service) in php:-
<$xmlJobList = "<?xml version='1.0'?><Search><CompanyId><![CDATA[ $companyId ]]></CompanyId>"; $xmlJobList .= "<Offset><![CDATA[ $offset ]]></Offset><Limit><![CDATA[ $limit ]]></Limit>";$xmlJobList .= "<Keywords><![CDATA[ $keywords ]]></Keywords>";$xmlJobList .= "<FunctionalAreaId><![CDATA[ $farea ]]></FunctionalAreaId>**<IndustryTypeIds>"; foreach ($industry as $value){$xmlJobList .= "<IndustryTypeId><![CDATA[ $value ]]></IndustryTypeId>";}$xmlJobList .= "<Format><![CDATA[ $format ]]></Format></Search>";
and i want to write the HTTP body for iPhone/objective-c
PLease help me for this, i am working very 1st time for php.
I'm working on a Zend project in a very specific server configuration, our production environment is made of two dedicated servers, one for the company's email which host a postfix server and an other server for our web-application which is running on Apache2/Zend.
Those servers have two different IPs, but works on the same website domain.
Now when i try to send an email with an email from the mail server as a sender, i get an error 500 from Zend_Mail and the email.err log tells me :
postfix/sendmail[15782]: fatal: -n option not supported
But when i put a local adresse or a blank email as a sender it works, so i guess i get kicked out by the postfix of the webserver because it doesn't manage localy those emails.
So my question is: is there any way to use a domain email as sender from a distant server without merging the two servers?
Edit: i forgot to add: i can't use the distant server SMTP, i only can use a local sendmail.
I haven't find any solution or explanations so i ended up by writing a custom action helper based on the mail command of PHP.
I hope it can help someone:
class Zend_Controller_Action_SentEmail extends Zend_Controller_Action_Helper_Abstract{
public function sendEmail($from, array $to, $subject, $message){
//Header set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: ".$from."<email#domain.com>\r\n";
$headers .= "X-Mailer: PHP/".phpversion();
//To
$stringTo = "";
foreach($to as $k => $v) {
$stringTo .= $k." <".$v.">, ";
}
$stringTo = trim($stringTo, ", ");
//Send the email
if(mail($stringTo, $subject, $message, $headers, "-f bounce#domain.com")){
return true;
}
else{
//Oh! Noes!
return false;
}
}
}