php - Twilio - Sending vCard Not Rendering Properly
Get the solution ↓↓↓I'm trying to send a contact card (.vcf) via Twilio (php) and can't seem to get the vcf to render properly.
The .vcf saves to my server fine, and if I subsequently download the file from the server and open in an iMessage on my iPhone or Mac, it displays just fine. But when sending via Twilio, all I see is the .vcf contents in plain text.
Here's the code I'm using:
$account_sid = 'xxxxxxxx';
$auth_token = 'xxxxxxxx';
$client = new Services_Twilio($account_sid, $auth_token);
header('content-type: text/vcard');
header('content-disposition: inline; filename= "testing2.vcf"');
try {
$vCard = "BEGIN:VCARD\r";
$vCard .= "VERSION:4.0\r";
$vCard .= "N:Gump;Forrest;;Mr.;\r";
$vCard .= "FN:Forrest Gump\r";
$vCard .= "ORG:Bubba Gump Shrimp Co.\r";
$vCard .= "TITLE:Shrimp Man\r";
$vCard .= "PHOTO;MEDIATYPE=image/gif:http://www.example.com/dir_photos/my_photo.gif\r";
$vCard .= "TEL;TYPE=work,voice;VALUE=uri:tel:+1-111-555-1212\r";
$vCard .= "TEL;TYPE=home,voice;VALUE=uri:tel:+1-404-555-1212\r";
$vCard .= "EMAIL:[email protected]\r";
$vCard .= "END:VCARD";
$path = '/var/www/xxxx/xxxx/testing2.vcf';
file_put_contents($path, $vCard);
$client->account->messages->create(array(
'To' => $user_mobile,
'MediaUrl' => ['https://www.example.com/vcfs/testing2.vcf'],
'From' => "xxxxxxxxxxxx"
));
}
catch (\Services_Twilio_RestException $e) {
}
EDIT
Here is the curl response I get from the URL used in MediaURL, indicating it is indeed a vcard format.
HTTP/1.1 200 OK
Date: Wed, 24 Feb 2021 04:13:29 GMT
Server: Apache/2.4.29 (Ubuntu)
Last-Modified: Tue, 23 Feb 2021 05:28:59 GMT
ETag: "15f-5bbfa320d710f"
Accept-Ranges: bytes
Content-Length: 351
Content-Type: text/vcard
Answer
Solution:
Make sure that the endpoint which serves your vCard sets the following headers:
Content-Type: text/vcard
,Cache-Control: no-cache
andContent-Disposition: inline; filename="filename.vcf"
See also this SO question: Generate VCard and Send Via Twilio
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: deprecated: directive 'allow_url_include' is deprecated in unknown on line 0
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.