Question: I want to calculate the dipole potential in spherical coordinates. I know that the potential can be calculated with 
$$ \phi = - \int \mathbf E \cdot\mathrm d\mathbf r,$$
but I don't know the electric field. I would say 
$$ \mathbf E = \frac{1}{4 \pi \epsilon\_0 r^3} ( 3p\,\hat{\mathbf {r}} \cos(\theta) -\mathbf p) $$
is the electric field in spherical coordinates but I'm not sure because I didn't calculate this formula, in fact I got it from a book and don't understand the way it's calculated.

Answer: 
The easiest derivation is probably to start with the potential, and then calculate the electric field as the gradient of that potential.

Consider a dipole at the origin aligned along the z-axis, with two point charges of charge $ \pm q $ positioned at $z = \pm\frac{a}{2}$. By symmetry, the potential will be independent of the azimuthal angle, so we only need to consider the potential at the coordinates $\left( r, \theta \right)$. Since we are trying to find the field around a point dipole, we can assume $r >> a$.

The distance of this point to the two charges is given by the cosine rule as $r\_\pm^2 = \frac{a^2}{4} + r^2 \mp ar \cos \theta$.

The potential at this point is then given by summing the potential from the two point charges, which is $V\left(r, \theta\right) = \frac{q}{4\pi\varepsilon\_0}\left(\left(\frac{a^2}{4} + r^2-ar\cos\theta\right)^{-\frac{1}{2}}-\left(\frac{a^2}{4} + r^2+ar\cos\theta\right)^{-\frac{1}{2}}\right)$. The approximation $r >> a$ suggests that we can Taylor expand this in $\frac{a}{r}$, and that is what we will do. 

Taylor expanding gives $V\left(r, \theta\right) = \frac{qa \cos \theta}{4\pi\varepsilon\_0 r^2}$. Any higher-order terms can always be ignored, because this is an ideal point dipole.

Now all that's left is finding the electric field from this potental. We know that $ \vec E = - \nabla V$. Taking the gradient of the dipole potential gives $\vec E = \frac{qa}{4 \pi \varepsilon\_0 r^3} \left( 2 \cos \theta \hat r + \sin \theta \hat \theta \right) $.

This is nice, but we'd like an expression in terms of the dipole moment; there aren't really any point charges separated by a physical distance, that was just scaffolding to get us this far. Fortunately, the way we've defined the coordinate axes gives us a nice expression for the dipole moment: $\vec p = qa \hat z$, or, in spherical coordinates, $\vec p = qa\left( \cos \theta \hat r - \sin \theta \hat \theta\right)$. So $ \vec p . \hat r = p \cos \theta = qa \cos \theta $.

Putting this all into the expression for the electric field gives us $ \frac{1}{4 \pi \varepsilon\_0 r^3} \left( 3p \cos \theta \hat r - \vec p \right)$, just as planned.
[![enter image description here](https://i.stack.imgur.com/5YhJT.jpg)](https://i.stack.imgur.com/5YhJT.jpg)

see above is a dipole with electric dipole moment $\mathbf{\vec{p}}$

since you know potential due to dipole it means 
$$\phi(r,\theta)=\dfrac { \mathbf{\vec{p}}\cdot\mathbf {\hat r}}{4\pi \epsilon\_{0}r^2}=\dfrac{p\cos\theta}{4\pi\epsilon\_{0}r^2}$$

To find radial component of field 
$$E\_{r}=-\dfrac{\partial \phi}{\partial r}=\dfrac{2\ p \cos\theta}{4\pi\epsilon\_{0}\ r^3}$$

To find angular component of electric field  

$$E\_{\theta }=-\frac{1}{r}\cdot\frac{\partial \phi}{\partial \theta}=\dfrac{p\sin\theta}{4\pi\epsilon\_{0}\ r^3}$$

therefore,

$$\mathbf{E}\_\text{dip}(r,\theta)=\dfrac{p}{4\pi\epsilon\_{0}\ r^3}\left(2\cos\theta\ \mathbf {{\hat r}}+\sin \theta\ \mathbf {\hat \theta}\right)$$ (in polar cordinate form)

$$\mathbf{E}\_\text{dip}=\dfrac{1}{4\pi\epsilon\_{0}\ r^3}\left(3(\mathbf {\vec p} \cdot \mathbf {{\hat r}})\mathbf{\hat r}-\mathbf{\vec p }\right)$$
(in coordinate free form)

$$\mathbf{E}\_\text{dip}(r,\theta)=\dfrac{1}{4\pi\epsilon\_{0}\ r^3}\left(3(p\cos\theta)\mathbf{\hat r}-\mathbf{\vec p }\right)$$