plPHP and php mail() example

From: Date: Fri, 30 Jan 2004 16:48:54 +0000
Subject: plPHP and php mail() example
Groups: php.db 
Request: Send a blank email to php-db+get-32718@lists.php.net to get a copy of this message
Here is a simple function that takes 4 arguments ($arg0-3) and utilizes the php mail() function. I added the headers for an example of how easy it is to utilize plPHP in PostgreSQL. CREATE OR REPLACE FUNCTION phpmail(text,text,text,text) RETURNS integer AS ' # Argument list $email_address = $arg0; $email_from = $arg1; $subject = $arg2; $body = $arg3; # # ..Typically, you would validate arguments here # Build email headers $headers = "From: $email_from\r\n"; $headers .= "Reply-To: $email_from\r\n"; $headers .= "X-Mailer: plPHP"; # Send email if (mail($email_address, $subject, $body, $headers)) {
    return 1;
} else {
    return 0;
} ' LANGUAGE 'plphp'; ############################################# # Usage ############################################# plphp_test=# SELECT phpmail('rrussell@commandprompt.com', 'webmaster@robbyrussell.com', 'Subject Line', 'This is the email body\n\nMore body. Testing email. Test!\n\n\n-Robby') as email; INFO: ret_val(long): 1 email -------
     1
(1 row) ############################################# # Output ############################################# webmaster@robbyrussell.com typed this on 01/30/2004 08:34 AM:
This is a body More body. Testing email. Test! -Robby
Feel free to join the plPHP mailing list as well. http://mail.commandprompt.com/mailman/listinfo/plphp Cheers, Robby Russell -- #------------------------------------------------------- # Robby Russell, | Sr. Administrator / Lead Programmer # Command Prompt, Inc. | http://www.commandprompt.com # rrussell@commandprompt.com | Telephone: (503) 667.4564 #-------------------------------------------------------

« previous php.db (#32718) next »