Share+mail file from php-script or command line

Hi there,

i prepare customer files using php script.
Afterwards a copy goes into the cloud, followed by a occ files:scan
now i want to share the new file using occ(?), set the expiration to 30days and let nextcloud send the link to the customer.

What would be the smoothest option?