Email not getting field info

karen

Member
I have created a custom button, and it works fine - it displays on the record page and sends the email once clicked.
I have a problem that when I send the email, it doesn't include the details of the record - I can get it to send with the record ID, eg 1, but not the actual details of the field.
I have at the top of the code
function dadabik_send_order($table_name, $where_field, $where_value) {
global $conn;

{
// Get the username of the logged-in user
$current_user = $_SESSION['logged_user_infos_ar']["id_user"];

and I have tried sql query to get the record info, but it doesn't show. Also I cannot get the details to show of the user's email address to add to the "from" and "reply to" field?
 

karen

Member
Hi, thanks deep64blue. This is the code, it worked before I put in the sql query, but now, the email doesn't send and I dont the message, I know the way I have put the sql query to get the fields is wrong, but I don't know how, or what to change:


// CUSTOM BUTTONS
$custom_buttons['Hoses'][$cnt]['type'] = 'php_standard';
$custom_buttons['Hoses'][$cnt]['callback_function'] = 'dadabik_send_order';
$custom_buttons['Hoses'][$cnt]['permission_needed'] = 'read';
$custom_buttons['Hoses'][$cnt]['show_in'][] = 'details_page';
$custom_buttons['Hoses'][$cnt]['position_form'] = 'top';
$custom_buttons['Hoses'][$cnt]['label_type'] = 'fixed';
$custom_buttons['Hoses'][$cnt]['label'] = 'CLICK HERE TO ORDER';
$custom_buttons['Hoses'][$cnt]['style'] = 'background:#c76128;width:200px';
$custom_buttons['Hoses'][$cnt]['id'] = 'order_now_button';
$cnt++;

function dadabik_send_order($table_name, $where_field, $where_value) {
global $conn;

// Get the username of the logged-in user
$current_user = $_SESSION['logged_user_infos_ar']["id_user"];

// Get the hose_id from the current record
$query = "SELECT hose_id FROM Hoses WHERE id = :where_value";
$stmt = $conn->prepare($query);
$stmt->bindParam(':where_value', $where_value);
$stmt->execute();
$hose_id = $stmt->fetchColumn();

// Get the email address of the logged-in user
$query = "SELECT email FROM dadabik_users WHERE id_user = :email_user";
$stmt = $conn->prepare($query);
$stmt->bindParam(':email_user', $current_user);
$stmt->execute();
$email = $stmt->fetchColumn();

// Set the recipient email address
$recipientEmail = 'sales@xxxxx.net';

// Set the subject of the email
$subject = 'New inquiry';

// Set the message body
$message = "Hose ID: $hose_id\n";
$message .= "User Email: $email_user\n";

// Set the headers
$headers = "From: your_email@example.com\r\n";

// Send the email
$mailSent = mail($recipientEmail, $subject, $message, $headers);

// Check if the email was sent successfully
if ($mailSent) {
echo 'Email sent successfully.';
} else {
echo 'Failed to send email.';
}

// Add code for returning to the previous page
echo '<a href="javascript:history.go(-1)">Return to previous page</a>';
}
 

karen

Member
Hi I'm going to re word this question and try again , I can't see how to delete the original question :(
 
Last edited:
Top