I want a code to send emails to the staff table without adding the email manually, do I find such a code with you? Thank you
- Please explain “send emails to the staff table without adding the email manually”, did you mean send emails to all staffs in the staff table (with email address field)?
- When do you want to send emails (in other words, where do you want to add your code)?
I would like to send an email to all employees using PHPMaker, can this be done?
There is no built-in feature to do that, you need to write your own code.
I’m thinking that the links should be above the users table
In addition to the existing icons (printer - export to PDF - …)
If another icon (link) is placed to send all mail to all users (for example).
All activated users - deactivated.
In the same way, this helps me a lot in sending emails in an easy way
PHPmaker is very powerful and can do almost any thing u can imagine in web 2.
Just be creative. Create a new table sendmail with id,subject,message
This is what i would do.
- on user table ,use server events : Page Data Rendering event to add your button or icon with a link to add page of another table.
function Page_DataRendering(&$header)
{
// Ignore $header just echo your button
echo' <style>.center {
margin: auto;
width: 60%;
padding: 10px;
background-color:#fff;
}
@media (max-width: 767px) {
.center{
width: 100%;
margin-left:-2px;
}
}
</style>
<div class="container-xxl center">
`<a class="btn btn-primary" href="sendmailadd" role="button">Send mail to all users</a>`
</div>
';
}
2 Now when you click the Send mail to all users button , you will be redirected to sendmailadd page with a form with fields subject and message .
3 Again use server event to send mails here.
// Email Sending event
function Email_Sending($email, $args)
{
// Get data from from input
$subject = $args["rsnew"]["subject"];
$message = $args["rsnew"]["message"];
// Get all users email
$allusersemail='';
// This gets all users email and add coma to the end of each email
//u can add your prefered where clause.
$conn = $GLOBALS["Conn"];
$sql = "SELECT DISTINCT email FROM `users` ";
$rows = $conn->executeQuery($sql)->fetchAll();
foreach ($rows as $row) {
$allusersemail .= $row['email'].',';
$email->Recipient = $allusersemail;
$email->Subject = $subject;
$email->Content = $message;
echo '
<html><script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script></html>
<script>swal("Success!", "Email Bulk Sending Completed !", "success")</script>
';
echo"<script>
setTimeout(function(){
window.location.href = 'userslist';
}, 2000);
</script>";
return true;
}
This will solve your problem. If you run into any issue post it here. Dont forget to TABLE > EMAIL NOTIFICATION >and check ON ADD
Thank you for your help, I want to check the codes.
User table named: emploloy
Field: (useremail) for mail
New table for emails named: sendmailtoemplloy
Selected the users table (emplloy) then (Table-specific) then (list-page) then (page_dataRendering)
This code was pasted after modification :
function Page_DataRendering(&$header)
{
// Ignore $header just echo your button
echo' <style>.center {
margin: auto;
width: 60%;
padding: 10px;
background-color:#fff;
}
@media (max-width: 767px) {
.center{
width: 100%;
margin-left:-2px;
}
}
</style>
<div class="container-xxl center">
<a class="btn btn-primary" href="sendmailtoemplloyadd" role="button">Send mail to all users</a>
</div>
';
}
Then for the other code
Selected the users table (emplloy) then (Table-specific) then (common) then (Email_Sending) then pasted this code after modification
This code was added after modification:
// Email Sending event
function Email_Sending($email, $args)
{
// Get data from from input
$subject = $args["rsnew"]["subject"];
$message = $args["rsnew"]["message"];
// Get all users email
$allusersemail='';
// This gets all users email and add coma to the end of each email
//u can add your prefered where clause.
$conn = $GLOBALS["Conn"];
$sql = "SELECT DISTINCT email FROM `emplloy` ";
$rows = $conn->executeQuery($sql)->fetchAll();
foreach ($rows as $row) {
$allusersemail .= $row['useremail'].',';
$email->Recipient = $allusersemail;
$email->Subject = $subject;
$email->Content = $message;
echo '
<html><script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script></html>
<script>swal("Success!", "Email Bulk Sending Completed !", "success")</script>
';
echo"<script>
setTimeout(function(){
window.location.href = 'emplloylist';
}, 2000);
</script>";
return true;
}
Parse error : syntax error, unexpected token “public” in D:\tm25.4.0\models\Emplloy.php on line 3120
This error appeared to me after doing the previous steps
Please correct me.
function Email_Sending($email, $args) { } is preloaded in your server events . make sure you did not nest the sample code inside the preloaded function. You can just clear the preloaded function and past the whole sample code. Also try to print out your Variables to be sure you are getting the right data
$allusersemail
$message
$subject
var_dump( $allusersemail);
exit;
do this for the 3 variables
You may also patse models\Emplloy.php here
i am sure your error is from a missing curly brace or added curly brace .
make sure your {} opens a nd close properly .
// Email Sending event
function Email_Sending($email, $args)
{
// Get data from from input
$subject = $args["rsnew"]["subject"];
$message = $args["rsnew"]["message"];
// Get all users email
$allusersemail='';
// This gets all users email and add coma to the end of each email
//u can add your prefered where clause.
$conn = $GLOBALS["Conn"];
$sql = "SELECT DISTINCT email FROM `emplloy` ";
$rows = $conn->executeQuery($sql)->fetchAll();
foreach ($rows as $row) {
$allusersemail .= $row['email'].',';
}
$email->Recipient = $allusersemail;
$email->Subject = $subject;
$email->Content = $message;
echo '
<html><script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script></html>
<script>swal("Success!", "Email Bulk Sending Completed !", "success")</script>
';
echo"<script>
setTimeout(function(){
window.location.href = 'emplloylist';
}, 2000);
</script>";
return true;
}
it is working now but no sending Email i try to send
$allusersemail
$message
$subject
var_dump( $allusersemail);
exit;
do this for the 3 variables
I am not a specialist and have little experience with editing
i do not know what do you mean about
Also try to print out your Variables to be sure you are getting the right data
UserTable Name : Emplloy
do i change $sql = "SELECT DISTINCT email FROM `emplloy` ";
to $sql = "emplloy"; ??
// Email Sending event
function Email_Sending($email, $args)
{
// Get data from from input
$subject = $args["rsnew"]["subject"];
$message = $args["rsnew"]["message"];
// Get all users email
$allusersemail='';
// This gets all users email and add coma to the end of each email
//u can add your prefered where clause.
$conn = $GLOBALS["Conn"];
$sql = "SELECT DISTINCT email FROM `emplloy` ";
$rows = $conn->executeQuery($sql)->fetchAll();
foreach ($rows as $row) {
$allusersemail .= $row['email'].',';
}
$email->Recipient = $allusersemail;
$email->Subject = $subject;
$email->Content = $message;
echo '
<html><script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script></html>
<script>swal("Success!", "Email Bulk Sending Completed !", "success")</script>
';
echo"<script>
setTimeout(function(){
window.location.href = 'emplloylist';
}, 2000);
</script>";
return true;
}
Any help please?
An email must have a “To”, “Cc”, or “Bcc” header.
and give me this message
no sending
This code should work well . I have used this on many projects . You should set your SMTP also check Email Settings if you are using webmail you can get device configuration on your cpanel. If you are using Gmail , google how to use gmail with PHPMailer .
var_dump() of variables is just to view your variable values with more info. you can just echo it if u dont like dump.
// Email Sending event
function Email_Sending($email, $args)
{
// this will but on sendmail Table with 2 fields (subject) and (message)
// Get data from input > This is a user table or any table that contains emails to send.
// usersemail leave it blank
// sql change usersemail to your Email feldName and chage users to your table users
//change active to your (active) field
// active users to send mail to active users only
//If you want to get all mail, delete WHERE active = '1' number 1 It means the activation entry.
//So the text will be as follows "SELECT DISTINCT usersemail FROM users"
//Make sure the case of the letters must be in sql and the fields are lowercase
//Make sure the case of the letters in the rest of the code must match the case of the letters in the fields, lowercase or uppercase
$allusersemail=''; //Do not change
$conn = $GLOBALS["Conn"]; //Do not change
$sql = "SELECT DISTINCT usersemail FROM users WHERE active = '1' ";
$rows = $conn->executeQuery($sql)->fetchAll();
foreach ($rows as $row) {
$allusersemail .= $row['usersemail'].',';
//($allusersemail .= $row['usersemail'].',';) change usersemail to you usersemail field do not chane $allusersemail
}
//
$email->Bcc = $allusersemail; //change Bcc to (Recipient) if you wnat emails go to Recipient with on email
//I prefer to send emails without other people knowing about each other.
//Don't forget to go to Tools > Advanced Settings > unCheck Use PHPMAILER
//This option works with Bcc. You do not need this option if you do not care about everyone receiving emails.
$email->Content = $args["new"]["message"]; //Change to the name of the custom field in the table, paying attention to the exact case of the letters, whether uppercase or lowercase. This advice applies to all codes.
$email->Subject = $args["new"]["subject"];
//Some terms used in sending emails
//$email->Sunder = $args["new"]["from "];
//$email->Cc = $args["new"]["cc "];
return true;
}