How do I send email from CGI scripts?
Scripts that run on our Web hosting servers should use the "Sendmail" program to send email. Almost all scripts that send mail have an option to use Sendmail — in fact, it's usually the default.
On this page:
- Path to sendmail
- E-mail script policies
- I'm writing a script. How do I use Sendmail?
- Can I use SMTP instead of Sendmail?
Path to sendmail
If you use a script that sends mail, it will probably ask you to enter the "path to Sendmail". On our servers, that path is:
/usr/sbin/sendmail
Be sure you understand our bulk mail policies, explained below, before you start sending any mail.
E-mail script policies
We do have some restrictions on the type of email that can be sent from scripts on the server.
It’s okay to send email from a script as long as the script can only send messages to a specific address that is a built-in part of the script (for example, the results of feedback forms).
However, to prevent strangers from abusing your script to send spam or harass others, you do have to follow specific rules and ask our permission before using scripts that can send email to other people. Our requirements for giving permission are:
- If your script sets a custom “envelope sender” address (aka “return address”, “bounce address” or “Return-Path”), that address must end with your domain name. See our page explaining the “Return-Path” for more information.
- The messages you send must not violate our spam policy. In particular, if the script adds the recipient to an ongoing mailing list, it must verify each address using a “confirmed opt-in” or “double opt-in” system, must maintain records of how each recipient verified the subscription request, and must include unsubscribe instructions with each message it sends.
- If the script is not a mailing list system (i.e., it sends one-time messages), it must prevent potential spammers from specifying both the recipient address and any of the message subject or body. It should also use a CAPTCHA to prevent “bots” from filling out the form with other people’s addresses, unless the form already does some kind of “prove you're human” test as a side-effect (such as an order form that requires a credit card number).
To get approval for a script that sends email to other people, just upload it to your website and contact us, telling us the name of the script and asking for permission to use it. If you’re using a mailing list you have already compiled, please provide details of how you verified each address (for example, by sending us the date and IP address used to confirm each subscription request).
I'm writing a script. How do I use Sendmail?
The two most common ways for programmers to use Sendmail are this method if the script specifies the destination address on the command line:
/usr/sbin/sendmail -oi -f 'from-address@example.com' 'to@example.com'
And this method if you want Sendmail to get the destination addresses from the "To", "CC" and "BCC" fields of the message itself:
/usr/sbin/sendmail -oi -t -f 'from-address@example.com'
For more Sendmail programming information, see the Sendmail documentation.
Can I use SMTP instead of Sendmail?
You should avoid using SMTP mail submission from scripts running on our servers if possible; always use /usr/sbin/sendmail
if the script supports it.
There's a very good reason for this. If you use SMTP, your script will fail to send email if the SMTP server is temporarily unavailable due to scheduled maintenance. That's because SMTP is designed for sending mail between mail servers that know how to try again a few minutes later if the receiving mail server is unavailable, but your script won't know how to do that.
In contrast, Sendmail is designed as a way for scripts to submit outgoing mail to mail servers. Sendmail accepts the mail from your script, stores it, and tries delivering it to the SMTP server. This normally takes just a fraction of a second, but Sendmail will happily keep trying for as long as necessary to successfully deliver your messages. Using it makes your script much more reliable.
If you do need to use SMTP, see the "Outgoing email settings" section of our email settings page for the necessary settings. But again: you really shouldn't do this. It won't work reliably.
Copyright © 2000-2024 Tiger Technologies LLC