Home >> Snippet List >> Snippet

Name
Use SendMail
Description
Talking to the mail program is like writing to a file (Perl programmers will be familiar with this technique) Instead of opening a file, the (popen() function specifies a program to pipe (communicate in a standard Unix way) your message to This makes a connection to the mail program The puts() function is used to "print" the message headers and message body out to the mail program, connected through the file descriptor already opened with the popen() function Because you may want to use a different mail program than sendmail, it's a good idea to store this path in variable You can store the recipient address in a variable to make it easy to change Here is a simple script to send a message by talking directly to the sendmail program
PHP Snippet
<?PHP
 
$fd = POPEN("/usr/sbin/sendmail -t","w");
   FPUTS($fd, "To: myaddress@domain.tld ");
   FPUTS($fd, "From: Me ");
   FPUTS($fd, "Subject: Test message from my web site ");
   FPUTS($fd, "X-Mailer: PHP3 ");
   FPUTS($fd, "Testing. ");
PCLOSE($fd);
 
?>