This topic is locked

Generate Email on Succesful Adding of Record

10/17/2005 8:58:58 PM
PHPRunner General questions
jimhnet author

You showed me the code to add a landing page on record completion, I would like at the same time to be able to generate an email to an email address in the record ie "Thanks for filling out the new information form we requested etc".
Thanks
Jim Freeman

Sergey Kornilov admin 10/18/2005

Jim,
you need to modify generated ..._add.php file. Find this line of code:

$message="<div class=message><<< "."Record was added"." >>></div>";


and insert the following just after it:

mail(  $_POST["value".array_search("email",$fieldlist)],

"type your subject here",

"type message text here");

?>

<script>

window.location="http://www.mydomain.com/index.html";;

</script>

<?php

return;


where "email" is your actual email address field. Please note, that this field name is case sensitive.

L
little44236 10/21/2005

I need to send an email to someone other than the person making the record so the email is in a different table. The person who needs to get the email is identified in the new record under an "attention" field and the email address is in a table "employees" where the "attention" matchs "ID_initials" and the email is in the "email" field.
Bob Small

Sergey Kornilov admin 10/24/2005

Bob
here is the snippet you can use.

$rsemail = db_query("select email from employees where ID_initials='".$_POST["value".array_search("attention",$fieldlist)]."'",$conn);

$dataemail = db_fetch_numarray($rsemail);

if($dataemail)

mail(  $dataemail[0],

"type your subject here",

"type message text here");

?>

<script>

window.location="http://www.mydomain.com/index.html";;

</script>

<?php

return;

L
little44236 10/26/2005

Looks like everything is working on this script except I am not getting an email. Do I need to have formmail turned on for it to work?
Bob Small

Sergey Kornilov admin 10/27/2005

Bob,
your PHP should be set up to send emails.
Here is the article on how to do that

http://www.php.net/mail

L
little44236 10/27/2005

My mistake. I had some field names wrong which is why it did not work. I fixed them and it works great. Thanks,
Bob Small