> where php code must be put in?
Simply think page-per-page and within each page from top to bottom. This is where the PHP code runs. And when the bottom of the page is reached, the page is sent to the respondent to collect answers.
So imagine, the PHP code was on the same page as the opt-in question. Then the server would create the HTML output for the opt-in question, then the PHP code runs, and then the page is sent to the respondent.
That means the the PHP code runs before the respondent even sees the opt-in question. The respondent cannot have answered it in that moment.
If you have a double-opt-in, and put the PHP code on the next page, the PHP code can know if the opt-in-question was answered. But it does not know if the respondent will click the confirmation button. To handle only confirmed answers, the PHP will has to be in another questionnaire that is run after the opt-in was confirmend.
> This interview has not been started in context of a mailing. Therefore, mailSchedule() cannot identify the appropriate recipient.
You have two options for the mailSchedule() function, first parameter. This can be the SERIAL of the respondent or "false" if the respondent is known to SoSci Survey. It is known when the interview was started via a personalized link - for example after the opt-in-confirmation. Otherwise, you must tell the function the SERIAL. Where do you get that from? Use value() with the ID of the opt-in question. Again, this won't work unless the opt-in question was asked and answered. That means the PHP code must not be on the same page.