In addition to any other e-mail address, incoming mail can also be forwarded as an HTTP request to a URL, which gives the possibility to programmatically process the mail.
For data security reasons, only URLs with the same domain as the referring email address can be used. Subdomains are also allowed.
For example, the referring address added to the name@example.com mailbox is https://example.com/mail_to_http.php
.
If the URL/file receiving the request is protected by Apache Basic auth (HTTP Authentication), its username and password must be appended to the URL in the form:
https://user:pwd@example.com/mail_to_http.php
You can add Mail-to-http redirection URLs in My Zone
control panel under Web-hosting
-> E-mail
-> Mailboxes
, then click on the mailbox and choose Forwarding
.
When a new email arrives, the server makes an HTTP POST request to the URL.
The $_POST
array variables are:
id (string): message id from (string): email sender's e-mail address to (string): email recipient's e-mail address headers (array): from (JSON object): email sender's name and e-mail address to (JSON array): email recipient's name and e-mail address date (string): sending time (RFC 2822) message_id (string): email unique Message-ID subject (string): email subject mail_to_http (array): from (string): email sender (SMTP protocol MAIL FROM:) rcpt (string): email recipient (SMTP protocol RCPT TO:) real_length (int): full length of the raw email (body) body (string): raw email (RFC822)
Email larger than 500 KB can be retrieved as .eml files from the $_FILES
array.
The fields in the $_FILES
array are typical of POST uploads:
PHP documentation: POST method uploads
$_FILES
array of variables are:
message (array): name (string): .eml file name type (string): email format type tmp_name (string): absolute path to temporary file error (string): error code size (string): file size in bytes
If the script or web server receiving the POST request returns the error code 5xx as the HTTP status code, the email server will keep the email in the queue and try to resend the email to the same URL after a while.