Forum Moderators: coopster

Message Too Old, No Replies

E-mail after PHP Script complete

         

vls_jr

2:34 am on Feb 17, 2005 (gmt 0)

10+ Year Member



Hey folks,

I need to replace a printf with some sort of e-mail function after a script has successfully been completed, but I'm not sure how to do that. Any help would be greatly appreciated.

Here's the code

<?

// Set a variable with the database name
$database_name = "MYDB";

// Attempt to connect to database and store result
$dbh = mysql_connect("localhost","username","password");

// Check the result of the connection attempt
if (!mysql_select_db($database_name)) {
echo "Can't Select $database_name";
}

// Conditional test to see if submit button was pressed
if ($enter_data) {

// Build our query string
$sql = "insert into users (fname, lname, yborn, gender, email) values
('$fname', '$lname', '$yborn', '$gender', '$email')";

// Execute a query and store the result
$res = mysql_query($sql,$dbh);

// Check to make sure the query actually ran
if (!$res) {
echo mysql_errno().": ". mysql_error ()."";
return 0;
}

printf("<p>Record successfully added</p>");
}

?>

Thanks!

jamesa

3:55 am on Feb 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use PHP's mail function [us2.php.net]. Minimal example:

mail("you@example.com","your subject", "your message");

or using variables:

mail($to_address,$subject, $message)
;

vls_jr

4:41 am on Feb 17, 2005 (gmt 0)

10+ Year Member



That works great! Thanks jamesa!