I'd like to recommend using the following temporary modification instead:
redirect($link);
exit;
This would be inserted just before this line:
$mail = new AMail($this->config);
redirect($link);
exit;
This would be inserted just before this line:
$mail = new AMail($this->config);