home | contact us
» » October


If you are struggling trying to get PHPMailer working with Google Apps then perhaps this is the solution for you.

I went to the PHPMailer site and found my way to a SourceForge download. After a lot of debugging and wrestling with this I just could not get it to work. In the end I looked at other projects that I knew were using PHPMailer for their mail and that were working with Google Apps or Gmail and found that their version was drastically more up to date than the one I downloaded from SourceForge.

In a nutshell – the version I had was never going to work.

A quick update later and I have PHPMailer working with Google Apps.

For reference the version here seems to be the up to date.

Here is some example code that IS working with Google Apps

<pre>
    <?php
    $to = 'info@edmondscommerce.co.uk';
    $message = 'testing swift mailer';

    require("class.phpmailer.php");

    $mail = new PHPMailer();

    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = 'tls';
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 587;

    $mail->Username = 'your@email.com';
    $mail->Password = 'yourpasswordwhatever';

    $mail->From = $to;
    $mail->FromName = 'test';
    $mail->Subject = 'test';
    $mail->WordWrap = 50; // set word wrap

    $mail->Body = eregi_replace("[\]", '', $message);

    $mail->IsHTML(true); // send as HTML
//To
    $mail->AddAddress($to);
    $mail->SMTPDebug = true;

    $mail->CharSet = 'us-ascii';
    $mail->Encoding = $mail->Charset != 'us-ascii' ? '8bit' : '7bit';

    if (!$mail->Send()) {
        echo "Message could not be sent. <p>";
        echo "Mailer Error: " . $mail->ErrorInfo;
        exit;
    }
    echo "Message has been sent";


 

Often we will be asked to work on a site and have to test backend features but without asking for admin passwords, so we need a way to create admin users without admin access. Of course we already have file and database access.

For this, we use phpmyadmin or adminer to give us database access and run the following php script at the commandline :-

<?php 
function Readln() {
  $handle = fopen('php://stdin','r');
  return rtrim(fgets($handle),"\n");
}

echo 'Enter username [or hit enter for "someadminuser"]: ';
$username = Readln();
if ("" == $username) {
  $username = 'someadminuser';
}
echo "\n";
echo 'Enter password [or hit enter for the usual one]: ';
$password = Readln();
echo "\n";
echo 'Enter table prefix [or hit enter for none]: ';
$prefix = Readln();
echo "\n";
$salt = 'EC'; 
echo "Salted is : ";
if (!empty($password)) {
  echo $hash = md5($salt.$password).':'.$salt;
} else {
  echo $hash = '20f808df3d6e913ec43164ad2e7be85e:EC';
}
echo "\n\n";
echo "SQL for insert : \n";
echo <<< EOT
insert into ${prefix}admin_user
select
(select max(user_id) + 1 from ${prefix}admin_user) user_id,
'Edmonds' first_name,
'Commerce' last_name,
'nojunkplease@mailinator.com' email,
'$username' username,
'$hash' password,
now() created,
NULL modified,
NULL logdate,
0 lognum,
0 reload_acl_flag,
1 is_active,
(select max(extra) from ${prefix}admin_user where extra is not null) extra;
 
insert into ${prefix}admin_role
select
(select max(role_id) + 1 from ${prefix}admin_role) role_id,
(select role_id from ${prefix}admin_role where role_name = 'Administrators') parent_id,
2 tree_level,
0 sort_order,
'U' role_type,
(select user_id from ${prefix}admin_user where username = '$username') user_id,
'$username' role_name
\n
\n
EOT;
?>

The output looks like this :-
Enter username [or hit enter for "someadminuser"]:
Enter password [or hit enter for the usual one]:
Enter table prefix [or hit enter for none]:

Salted is : 20f808df3d6e913ec43164ad2e7be85e:EC

SQL for insert :
insert into admin_user
select
(select max(user_id) + 1 from admin_user) user_id,
'Edmonds' first_name,
'Commerce' last_name,
'nojunkplease@mailinator.com' email,
'someadminuser' username,
'20f808df3d6e913ec43164ad2e7be85e:EC' password,
now() created,
NULL modified,
NULL logdate,
0 lognum,
0 reload_acl_flag,
1 is_active,
(select max(extra) from admin_user where extra is not null) extra;

insert into admin_role
select
(select max(role_id) + 1 from admin_role) role_id,
(select role_id from admin_role where role_name = 'Administrators') parent_id,
2 tree_level,
0 sort_order,
'U' role_type,
(select user_id from admin_user where username = 'someadminuser') user_id,
'someadminuser' role_name

Which we can then copy and paste into the database admin. No prizes for guessing the first programming language of the dev who wrote the script.


 

If you use Linux on a regular basis, you’ll probably know just how useful a symlink is.

This makes things extremely annoying when a program refuses to work with them – treats them as a file or just refuses to work.

Enter: mount –bind

mount –bind is a special type of mount that will mount one directory as a child of another. Quite often this is used for simplifying partitioning or if a cpanel server runs out of disk space.

The general usage at the commandline is :-
mount --bind olddir newdir

and in the fstab :-
olddir newdir none defaults,bind 0 0

For instance, setting up a system where /home, /var and /opt share a partition and everything else is on another can be done like this in your fstab :-

#root fs
UUID=ebb8043d-6f1e-4a65-8d73-2c05f7ec213a / xfs defaults 0 1
#two tibibyte partition
UUID=6210e43f-83a3-4001-83c7-40e3b1fb9c8e /twotib xfs defaults 0 2
# Following binds
/twotib/home /home none defaults,bind 0 0
/twotib/opt /opt none defaults,bind 0 0
/twotib/var /var none defaults,bind 0 0


 

It may be obvious but after a discussion in the office we decided to put together a simple guideline for getting into e-commerce.

This is a list of things that you need to do in order to start selling from your own web site.

Get a Domain Name
These are so cheap yet so fundamentally important it really should be one of the first things you do. Always ensure you can get the .com even if you intend to run from the .co.uk. If budget allows, buy all the top level domains you can afford simply to ensure they are yours – eg .com, .net, .co.uk, .org.uk, .info etc etc.

Find a Supplier
The first thing you need is a supplier that you can buy from cheap enough to markup and earn a reasonable profit. Often this is one of the hardest bits, especially when you are starting out, finding a supplier that will agree to supply you can be tough. Be prepared to pay for stock up front initially and also to take on stock holdings.

You May need Retail Shop
Even though you intend to make ecommerce the primary focus of your business, you may find some suppliers simply will not work with you if you do not have a retail shop. You need to double check this. Some times it is enough to have a few counters or a display rack in your warehouse, or some kind of “trade counter”. Other times you may really need a plate glass high street store front to get supply.

Decide on your Fulfillment
You need to decide how you are going to fulfill customer orders. Are you going to do everything yourself? Are you going to use a fulfilment company to take care of this for you. You may find that your supplier(s) offer a drop shipping service where they will fulfill orders directly for you.

Decide on Shipping Methods and Charges
Are you going to offer next day courier? Do you need to worry about insurance? Can you get away with Royal Mail? There are lots of things to consider when thinking about this aspect of the business.

Merchant Account
If you want to take credit card payments, and any serious ecommerce business should – I definitely believe it is not enough to simply offer paypal – then you are going to need a merchant account. You will also need a business account – these do not have to be from the same bank, though they would have you believe they do. Shop around for the best rates – this can have a distinct impact on your bottom line, especially if margins are tight.

Payment Service Provider
The payment service provider is the system that will actually allow customers to enter card details and will report transactions back to your merchant account. Again its worth shopping around for the best rates. Bear in mind you can only have one PSP per merchant account.

Choose your Shopping Cart Platform
You need to choose which platform you want to base the site on. Choices generally include Magento which is without a doubt the most popular and powerful, Open Cart, osCommerce and derivatives are still popular though not really for new sites these days.

Get a Design
Your choices for design range from using an off the shelf theme which is the cheapest option through to getting a full custom design created. If you are looking for templates, simply search google for {platform} template or {platform} theme. For example Magento Templates.

Implement your design on your Cart
If you have chosen a template then this is usually a case of installing that template and then making whatever customisations you want/need to make in order to brand the site with your logos, colour schemes etc. If you have chosen to go for a custom design then this is a much larger task but the end result is something that is exactly what you want. This is definitely something that Edmonds Commerce can help you with.

Load your Product Data
You need to populate your store with product information. In its barest form this should include name, description, SKU, price and images. You may find getting the data is tricky. Alternatively you may be lucky enough to have suppliers that offer a full data feed and images for their products making this very easy. If you need to bridge the gap, getting a custom scraper built to get product data from your suppliers web sites can be a very cost effective solution.

Choose a Hosting Company
Whilst your store is in development you will not generally need hosting. All of our client work is carried out on our local environment and staging server. It is only when the site is ready to go live that hosting is required. When choosing a host there is lots to consider. The first and most obvious is the hardware spec of your server. Are you going to go for the cheapest shared hosting, a VPS with reasonable power or a dedicated with large RAM and CPU resources?

The other big question that I think a lot of people do not consider in enough detail is the level of support you need from your hosting company. This has a dramatic impact on the price. It’s possible to get a very powerful dedicated for around the £100 per month mark. However don’t bother calling the support line at 2am on a Saturday Morning. If you need full phone support, especially 24/7 then expect to pay for this. I would also advise trying to ring the support lines at these kinds of times just to check that it really is there.

Launch Your Store
You can launch your store as soon as you have product data and a means of payment set up and the store is accessible by visiting your domain name. There are different schools of thought on when you should launch. One is that you should not launch until your site is 100% finished and ready to impress your visitors with its sheer amazingness. Another school of thought is that you should launch ASAP to allow search engine spiders to get in and also to allow visitors to start trickling in allowing you to ensure your systems are all working properly before you switch on the more powerful marketing that will drive large traffic.

Register Self Employed
If you are starting out in business you need to remember to register yourself as self employed with the revenue. Here is some more info.

Unleash the Marketing
Your store will not succeed unless you have an effective marketing strategy in place. This could involve simply SEO + PPC or might extend through to TV adverts, billboards etc. The main differentiator is scale and budget. SEO is a long term strategy, it is unlikley you will achieve great results from the get go. PPC offers an instant response though the costs can be very high so maintaining profitability can be a concern.

Continuous Improvement
Once your ecommerce business is up and running you should commit yourself to a continuous cycle of improvement. It’s the only way to ensure you stay ahead of the game and achieve the level of progress you desire.

You need to plan on the fact that you will need to periodically upgrade your shopping cart. Especially if you are using Magento – it is being updated all the time.


 

Perhaps not as well known as it should be, PHP’s glob() function is really quite powerful and exceptionally handy.

Need to get a list of files in a directory – try this:

$tools = glob('includes/tools/*');
var_dump($tools);

Want to delete all files matching a specific pattern, try this:

array_map('unlink', glob('export_feeds/my_feed_*'));

Theres lots more tricks you can do.

One word of warning though – with great power comes great responsibility!

I would advise against using any kind of user input with this function.

Read more


 

If you use Netbeans along with Xdebug to facilitate step through debugging when coding PHP then you may come across this issue.

It’s possible to get it into a semi working scenario where you can have working breakpoints and see variable values but you have no idea which bit of code you are actually stepped up to.

This can happen if your server path and project path are not correctly configured.

To resolve this simply go to your project properties, run configuration and then hit the advanced button.

The server path should be the absolute path to the project root on the server (eg /home/server/sites/blah/) and the project path should be the path on your local machine to the project files (eg /home/joseph/projects/blah/).

Stop any debugging sessions and then start another one up and if you have the paths set right, you should get the behaviour you expect where Netbeans highlights the current line of code and allows you to step through the code to figure out what’s going on.


 

If you need to test your code against the (ahem) interesting interpretations of the various iterations of Internet Explorer then this is a great resource for you.

Turns out Microsoft have thrown web devs a bone by offering free virtual machine images with the various IE/OS flavours for you to test on. You can download them here.

If you use VirtualBox and also a *nix based operating system such as Linux or OSX then you can use this, frankly awesome, bash script to automatically download one or all of these machines and fully set them up in VirtualBox for you.

VirtualBox, if you are not aware, is a freely available Virtualisation platform allowing you to run other operating systems on your desktop. On todays powerful machines its perfectly easy to run Linux as your core operating system and then for either running windows only apps or for testing dodgy browsers, you can fire up one of these VMs.

Bear in mind that they are not for keeps, you will need to reset them every 30 days due to the fact that they can not be activated. For our purposes though this is not really a problem.

Usage

Please note all of this has been copied and pasted from here. Posted here for reference only, all original attribution and credit goes to webupd8.

1. Before proceeding, make sure you have the latest VirtualBox installed – you can find Ubuntu installation instructions HERE. You’ll also need “curl” (for both Linux and OSX) and “unrar” (Linux only). In Ubuntu, install them using the command below:

sudo apt-get install curl unrar

2. To download and run the CODE, use the following command in a terminal:

curl -s https://raw.github.com/xdissent/ievms/master/ievms.sh | bash

If you want to check out the bash source before running it, you can find it @ GitHub.

The above command will download Windows WHDs for IE7, IE8 and IE9. If you only need one Internet Explorer version, you can run:

curl -s https://raw.github.com/xdissent/ievms/master/ievms.sh | IEVMS_VERSIONS="9" bash

Where “9″ is the IE version you want (you can also add two versions here, like “7 9″).

At this point, the download should start and it will take a while so be patient.


 

If you need to update a large number of rows on a single table then your first reaction may be to write a loop that updates one row at a time.

Of course if the table is large then this can result in a very large number of SQL queries.

Taking a bit of inspiration from this post I have put together this simple PHP function that will allow you to update as many rows as you want.

The trade off is basically memory usage as you build up a big array of row update information preparing for the batch. For this reason you may want to tune the number of rows you update per query.

function bulkUpdateSingleColumn($table, $id_column, $update_column, array &$idstovals){
        $sql = "update $table set $update_column = CASE $id_column ";
        foreach($idstovals as $id=>$val){
            $sql .= " WHEN '$id' THEN '$val' \n";
        }
        $sql .= " END 
        WHERE $id_column in (" . implode(',', array_keys($idstovals)) . ")";
//debugging info
        echo '<small>'.$sql.'</small>';
        $idstovals=array();        
        db_query($sql);       
        done();        
    }

 

Some times you might have a legacy system that is built around csv or similar and you need to import an XML data source into this system.

Of course one possibility is to build full XML handling capabilities into the system. Perhaps a more sane solution is to simply convert the XML to CSV so that the legacy system does not have to be touched.

This little snippet will generally take an XML file and create a CSV file that should be useable. Of course its impossible to guarantee this for every XML file as its such a widely varied format, however in general this should work.

$xml = simplexml_load_file('feed.xml');
$outstream = fopen('feed.csv','w');
$header=false;
foreach($xml as $k=>$details){
    if(!$header){
        fputcsv($outstream,array_keys(get_object_vars($details)));
        $header=true;
    }
    fputcsv($outstream,get_object_vars($details));
}
fclose($outstream);

 

So now that everyone uses Google Shopping, Google are making life difficult for the merchants and they all have to jump through hoops.

The current push from Google is enforcing some things that are very difficult for small companies to conform with :-

* EAN Numbers – This is the BIG one, Google are making EAN Numbers required – for some retailers, they just don’t exist, and for a lot of older or cheaper shopping cart systems, they don’t have anywhere to enter them.
* Google Category – This is a fairly obvious one, they are attempting to enable shoppers to browse products and find a motherboard for instance with a 1156 socket rather than a CPU that fits an 1156 socket. The answer is to add an extra field to a site’s category system to map site categories to Google categories, or to restructure your products into google’s categorisations.
* Product Images – Google are making this mandatory as well, which most people are getting round by using stock or illustration-only images.
* Availability – This one actually helps retailers, putting orderable products that are out of stock in front of customers, and is a small change to most scripts exporting to Google

The above changes are being phased in now but should your feed suddenly stop working, how big is the impact on your business? Whilst some of the changes are little tweaks, such as the availability flag, others require fairly substantial changes in the back-end of many cart systems. We are getting many aggrieved businesses contacting us asking for fast turnaround on their Google products feed as they are loosing money all the time that Google are rejecting their products.

What normally (given past changes) has been little tweaks for feeds to be compatible has lately become hours and hours of work both on developers and store-owners. Are you ready to jump through the latest burning hoop Google is holding out for you?


 
rss icon