Why do t-test use standard error and not standard deviation? Maybe the solution is obvious, but I don't fully understand why. Is it related with the fact that the SE takes into account the sample size? 
 A: You already have the answer. The SE is computed from the SD and the sample size. A t test has to account for sample size. It does so in two ways. One is that the calculation of P from t depends on sample size, but not very much. The main way that sample size enters the t test calculations is in computation of the standard error (or in calculations that use the SD and n, which amount to the same thing).
The P value computed from a t test (and the width of the confidence interval for the difference between means) is computed from three values: The magnitude of the observed mean difference, the standard deviation within the two groups, and the sample size of the two groups. 
A: The sample standard deviation is the deviation of the individual data points from the sample mean. When doing inferential statistics we want to be able to say something about population means and not about individual data points. So what we need is a measure of the variability of all possible sample means instead of the standard deviation of individual data points.  
Theoretically, we could get such a measure by randomly sampling the population over and over again and calculate the sample mean every time, which will generate the sampling distribution of the sample means for which you could calculate the standard deviation of sample means, or you can approximate this variability by using the standard error of the mean, which is calculated as the sample standard deviation divided by the square root of the sample size.
That's why the standard error of the mean is used (and not the sample standard deviation) to calculate the t-statistic.
