The simple answer to this question is that Viagra is legal when it is produced by Pfizer (the manufacturer) for use in the country or region in which it is sold and supplied with instructions for the user in the national language.
The addendum to this definition is that in the European Union, Viagra and the other erectile dysfunction/impotence products - Cialis and Levitra, are controlled drugs that can only be supplied on a prescription issued by a suitably qualified person (generally an E U recognised doctor).
The European Union decrees that there should be freedom of supply from one member state to another of controlled drugs, provided they are covered by the relevant legislation of the issuing country and have not been prohibited in the destination country. This means that Viagra, Cialis or Levitra purchased with a valid prescription in an EU country of origin can be sent freely between other countries in the EU. The drugs must be accompanied by identifying paperwork that is available to customs authorities, who may want to check that it is legal product from an EU source.
In some instances vat may be payable outside of the United Kingdom on medicines sourced outside the UK, but never within the UK on prescription medicines such as Viagra, Cialis or Levitra originating in the UK.
Viagra for individual personal use for impotence is legal in the UK or EU member states if it originates inside of the EU and was issued on a valid prescription. In all cases not like this, i.e. coming from outside the EU, customs will confiscate without compensation if they discover the parcel.
It is also extremely dangerous to supply prescription drugs without first having a consultation carried out by a qualified doctor. Under UK law, this can be done at a distance and over the Internet if the patient chooses to do it that way, and the doctor agrees.
Always ensure that you are asked to complete a consultation first and that the supplying company is EU based and preferably UK based.
If you can't be sure of all this, then do not buy. Impotence will be the least of your problems if you get your hands on some poor quality medicine from a ruthless criminal source.
Cheap is nearly always fake and often dangerous.