Mehdi,
I believe your php is correct as far as I can see. The final section is needed since you are dropping out of php to produce the form (not how I would have done it, but I don’t see any errors) and need to drop back into php to have the final curly brace -- leaving it out would produce a php syntax error.
Here’s a quick look at another way to do it.
<?php
$output = "";
if form submitted {
//send the email here
$output .= "your message has been sent";
} else {
$output .="<form>";
// $output .= your form here
$output .="</form>;
}
return $output;
As far as the URL, I think this will do what you want:
$url = $modx->makeUrl([~id~], '', '', 'full');
Note that the second and third arguments are two single quotes not a double quote as they might appear.
I also wanted to mention a few other things.
First, it apppears that, as written, the page can be pretty easily hijacked since all it looks for is a submit and uses whatever _POST variables it gets. I’m not a mail hijacking expert but it looks like someone could pretty easily send zillions of messages through your page to various people they want to annoy and they would all appear to be coming from you.
Second, many ISPs now have the PHP mail() function turned off so the page would appear to work, but no mail would be sent. MODx has its own mail function that includes an SMTP alternative but that would involve some more complicated code and parameters in the snippet call to tell the snippet whether to use mail() or SMTP.
Hope this helps,
Bob