phpgoogle-visualizationqr-codevcf-vcard

Creating vCard QR Code


I've got a PHP script that generates a business card template from details entered on the website.

We've recently decided to add QR Code vCards to the business cards as an easy way to save contact info. I am using this tutorial as a starting point.

However, my QR Code does not work. It keeps giving me no result and format as text.

Here is the script that creates the vcard and displays the qr code:

$vcard = "BEGIN:VCARD\r\nVERSION:3.0\r\n
N:" . $_POST['surname'] . ";" . $_POST['name'] . "\r\n
FN:" . $_POST['name'] . " " . $_POST['surname'] . "\r\n
ORG:Example Organisation\r\n
TITLE:" . $_POST['position'] . " [" . $_POST['qualification'] . "]\r\n
TEL;TYPE=work,voice:" . $_POST['telephone'] . "\r\n
TEL;TYPE=cell,voice:" . $_POST['cellno'] . "\r\n
TEL;TYPE=work,fax:" . $_POST['fax'] . "\r\n
URL;TYPE=work:www.example.com\r\n
EMAIL;TYPE=internet,pref:" . $_POST['email'] . "\r\n
REV:" . date('Ymd') . "T195243Z\r\n
END:VCARD";

echo '<img src="http://chart.apis.google.com/chart?chs=500x500&cht=qr&chld=H&chl="' . urlencode($vcard) . '"/>';

Any assistance?


Solution

  • The double quote is being encoded into the QR Code, it should work if you remove these (and should avoid error as any special characters are encoded).

    Removing the quotes gives me this QR Code which seems to work:

    QR Code