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('[EMAIL PROTECTED]', '[EMAIL PROTECTED]', '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
#############################################
[EMAIL PROTECTED] 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
# [EMAIL PROTECTED] | Telephone: (503) 667.4564
#-------------------------------------------------------

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to