Basic script for email/custom button

karen

Member
Hi all, hoping for some assistance with an example script. I have been trying for about 3 days to get this to work and I'm tearing out my hair.
I have made a custom button that works, and is displayed on the record details page. I can get it to send a blank email..

All I need to do is send all fields of the currently displayed record to a fixed email address. The "from" and "reply to" in the email need to be those of the currently logged in users.
I know this should be SO simple, and I'm trying to learn php at the same time as developing the app, but this is really making me feel stupid.
If anyone has a script already that does this function, I'm hoping to save another 3 days of my life by using it as a template. I've read the documentation, but there's nothing specific about how to do the sql bit to get the current record. Please can anyone help? Thank you.
 

karen

Member
Hi sorry what do you mean by details of the installation, you mean what is the function of the website?
 

deep64blue

DaDaBIK Guru
I mean the about info from within the application, this tells us what version of dadabik etc you are running.
 

karen

Member
Oh sorry, I thought all that was displayed in my signature.. doesn't it show at the end of my posts?
 

deep64blue

DaDaBIK Guru
This is my email script, it triggers from a database update but hopefully it will help you. The email is sent from noreply@mydomain, I haven't looked into changing that.

$hooks['mem_subs']['insert']['after'] = 'dadabik_subspaid';

function dadabik_subspaid($id)
{
global $conn;

$sql = "SELECT `preacher`, `memtype`, `paid`,`year`, `ID_User` FROM `mem_subs` WHERE `subsID`=:id";

$res_prepare = prepare_db($conn, $sql);

$res_bind = bind_param_db($res_prepare, ':id', $id);

$res = execute_prepared_db($res_prepare,0);

$row = fetch_row_db($res_prepare);

mail ('subs@sblpa.co.uk', 'SBLPA Subs Updated', $row['year'].' subs status has been set to '.$row['paid'].' for '.$row['preacher']. ' by '.$row['ID_User']);

//Update timestamp for home page
$sql = "INSERT INTO `zz_check` (`id`, `myvalue`) VALUES (NULL, '$id')";
$res_prepare = prepare_db($conn, $sql);
$res = execute_prepared_db($res_prepare,0);


}
 

karen

Member
Thanks Guru!! It's a bit late for my little brain now, but I'll get on it tomorrow. I will get this email to work if it's the last thing I do.
I really appreciate you taking the time to help me.
 

deep64blue

DaDaBIK Guru
The email is sent from noreply@mydomain, I haven't looked into changing that.
I haven't tested it but this has been suggested as a solution:-
PHP:
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
 

karen

Member
Hi deep64blue, all working now!! A lot of fiddling with codes and finally fixed the bit that was causing the issue:

$stmt = $conn->prepare($query);
$stmt->bindParam(':where_value', $where_value);
$stmt->execute();
$hose_id = $stmt->fetchColumn();

I have a new problem now with another php custom function to generate a qrcode, that I wasn't going to add, however, my misplaced confidence of getting this one to work made me think it would be easy!! I might be back later...
Thanks once again for your help!
 
Top