How would i pull zend mail addresses from a table - zend-framework

I have a .php file that has a list of email addresses in zend_mail. When a user sends out an alert message, say a bus broke down, the alert goes to my database and everyone on the email list. I would like the email addresses to come from table rather than be hard coded into the php file
We are only hard coding right now, sometimes twenty addresses, for each php file
try {
$mail = new Zend_Mail();
$mail->addTo('johnnywalker#comcast.net');
$mail->addTo('mjimeez#thistransportation.com');
$mail->addTo('aburrow#thistransportation.com');
If the code were to say try{ from mytable which contains a list of addresses in column a,where column b = 1,representing which php files go to which employees

$sql = $dbRead->quoteInto("SELECT alertID,[alertDescription],count(*) as [Count] FROM dbo.ActiveAlerts WHERE subdomain = ? GROUP by alertID, [alertDescription]",$subdomain);
$resultAlerts = $dbRead->fetchAll($sql);
foreach($resultAlerts as $x){$alertIDs .= $x['alertID']."|";}; //load for controller
Then this adds it to the table
$alertID = "1001"; //incident updates
if(strstr($alertIDsOK,$alertID)) {
try {
$sql = $dbRead->quoteInto("SELECT email FROM dbo.ActiveAlerts WHERE alertID = ?",$alertID);
$resultEmail = $dbRead->fetchAll($sql);
$mail = new Zend_Mail();
foreach($resultEmail as $m){
$mail->addTo($m['email']);}

Related

Google Contacts Fields to fill variables in email template

First of all, thank you for your time.
I have been looking for a while for a program, a script or anything that could help me automate a task that otherwise is going to take very long.
See, i'm a french computer technician working for almost exclusively doctors here in France.
The doctors receive results by email, the results are then imported to the patient's folder from the email automatically.
But in order for them to receive that information we have to communicate an email address from a special domain + the doctor's ID that is like your driver's ID.
We use google contact as an address book because it's convenient. Since whenever we make a new maintenance contract with a doctor we input everything to google contact the info is already there. Sometimes we have up to 20 doctors in the same cabinet to set.
Link to a Google Sheet Contact Sample
The fields are the following :
Structure's Name : {{contact company name}} (all the doctors share the same structure)
Strutre's Adress : {{contact full address}} (all the doctors share the same structure)
First doctor
Last Name : {{last_name}}
First Name : {{first_name}}
eMail Address : {{email_address}} (this one is tagged MSSANTE in ggC)
Doc's ID : {{custom_field}} (this is a custom field tagged RPPS in ggC)
Second doctor
Last Name : {{last_name}}
First Name : {{first_name}}
eMail Address : {{email_address}} (this one is tagged MSSANTE in ggC)
Doc's ID : {{custom_field}} (this is a custom field tagged RPPS in ggC)
So on and so on.
Then this as to be sent to many laboratories all in BCC and the customers/doctors usually in CC
I was thinking of using google sheets or google's people API somehow...
Can someone give me a strategy or some code to start ?
Again thanks to anyone who can help even a bit.
Try
function email() {
const ss = SpreadsheetApp.getActiveSpreadsheet()
const emails = ss.getSheetByName('LABS mails').getRange('C2:C').getValues().flat().filter(r => r != '').join(',')
MailApp.sendEmail({
to: emails,
subject: 'titre du mail',
htmlBody: body()
})
}
function body() {
const ss = SpreadsheetApp.getActiveSpreadsheet()
const template = ss.getSheetByName('Mail Template (Exemple)')
const docteurs = ss.getSheetByName('Doctors')
let [headers, ...data] = docteurs.getDataRange().getDisplayValues()
let debut = template.getRange('A2:A').getValues().flat().filter(r => r != '').join('<br>')
let variable = template.getRange('B2:B').getValues().flat().filter(r => r != '').join('<br>')
let fin = template.getRange('C2:C').getValues().flat().filter(r => r != '').join('<br>')
const liste = ['{CABINET}', '{NOM}', '{PRENOM}', '{EMAIL}', '{RPPS}']
const colonnes = [1,4,3,8,7]
let message = debut
data.forEach((r, row) => {
var texte = variable
for (var i = 0; i < liste.length; i++) {
texte = texte.replace(liste[i], r[+colonnes[i] - 1])
}
message += texte + '<br><br>'
})
message += fin
return (message)
}
Put the text as follows (you will need a little html tags)
The email will be

What is the proper way to use a findBy’Field’ method?

I am trying to compare an email address inputed from a form to what is already in the database and I figure the best way to do so is with using a findByEmail method.
I expected that to find the email address for a specific entry in the table but instead it returns the whole entry (first name, last name, and more…).
How do I only find the email address of the entry in the table?
I know I can use a foreach to iterate through the entry but I think that kinda defeats the purpose of using a findByEmail function.
Here’s what I’ve tried so far:
$formEmail = $form->get('email')->getData();
$personEmail = $em->getRepository('UserBundle:User')->findByEmail($formEmail); //Should just find the email address of a person in the database.
var_dump($personsEmail); //returns the whole row associated with the email address (first name, last name…..)
var_dump(if($formEmail == $personEmail));die; //returns false when it should be true because it finds the whole row instead of the email address
If you fetched the entity successfully by email then the email must match.
$formEmail = $form->get('email')->getData();
$person = $em->getRepository('UserBundle:User')->findOneByEmail($formEmail);
if ($person instanceof User) {
// you found a user by email, so the email therefore must match ...
}
Note, use findOneBy not findBy, then you will fetch the object directly instead of in a collection.
Alternatively if you must fetch just the email address for comparison.
$email = $em->createQueryBuilder()
->select('u.email')
->from('UserBundle:User', 'u')
->where('u.email = :email')
->setParameter('email', $formEmail)
->getQuery()
->getSingleScalarResult()
;
Note though that you could just use $person->getEmail() in my first example for the same result.

Use tt_address fields in direct_mail newsletter

I am using TYPO3 6.2.11, tt_address 2.3.5 and direct_mail 4.0.1 and sent me some test newsletters from a internal TYPO3-Page. Everything works fine.
Now, I want to send some data fields from my tt_address-table like name or title for example.
What's the name of the tt_address-MARKER, I'll use at my page content?
I also add the follwing to [basic.addRecipFields] at the direct_mail-Extension:
name,first_name,last_name,email,description,title
But nothing happens. I can't use tt_address-fields at my direct_mail newsletter. I hope someone can help me, thanks.
The other opportunity is to use fe_user-data for my newsletter (felogin). How can I use felogin-fields like passwordor username at my template?
You need to prefix the fields with USER_ and wrap the marker in ###. So e.g. if you'd like to use the e-mail address, you write ###USER_email###. You can find all possibilities in the Direct Mail documentation.
A note on sending the password: This would be a huge security risk but it's not possible anyway because passwords of fe_users are stored at least hashed (and nowadays also encrypted) in the database. But you can use the ###SYS_AUTHCODE### marker to generate an authentication code you can use in an "edit profile" extension to let the user update his subscription.
If you need fields from other sources or data you're calculating dynamically, you can also create an own extension and implement the Direct Mail mailMarkersHook.
ext_localconf.php:
// Direct Mail personalization hook
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/direct_mail']['res/scripts/class.dmailer.php']['mailMarkersHook']['userunilunewsletterrendering'] =
'My\Extension\Hook\DirectMail->mailMarkersHook';
EXT:extension/Classes/Hook/DirectMail.php:
<?php
namespace My\Extension\Hook;
class DirectMail {
public function mailMarkersHook($params, \DirectMailTeam\DirectMail\Dmailer $dmailer) {
$params['markers']['###USER_SALUTATION###'] = $this->getPersonalizedSalutation($params['row']);
return $params;
}
/**
* #param $row
* #return string
*/
protected function getPersonalizedSalutation($row) {
$personalizedSalutation = 'Dear Sir or Madam';
if (!empty($row['last_name']) && !empty($row['gender'])) {
if ($row['gender'] === 'm') {
$personalizedSalutation = 'Dear Mr. ' . $row['last_name'];
} elseif ($row['gender'] === 'f') {
$personalizedSalutation = 'Dear Ms. ' . $row['last_name'];
}
}
return $personalizedSalutation;
}
}

Where is my num_rows failing?

<?php
$link = mysqli_connect('localhost','root','root');
$link->query('CREATE DATABASE IF NOT EXISTS users');
$link->Select_db('users');
$sql='SELECT id FROM users WHERE email = '.$useremail.' AND username = '.$username;
$results = $link->query($sql);
$numrows = $results->num_rows;
if ($numrows == 1) {
#update user information
} else {
#failed to update
}
?>
It only works part of the time, and i'm not able to nail down an error from it one way or the other. I can confirm that the error pops up on the $numrows=$results->num_rows; line, but as for why, i'm lost. Occasionally it will work as intended, so any and all advice on what i can do to fix it, or at least helping me understand it better is greatly appreciated. Thanks!
Use Double Quotation for query and varchar/string pass with single quotation
$sql="SELECT id FROM users WHERE email = '".$useremail."' AND username = '".$username."'";
$results = $link->query($sql);
$numrows = $results->num_rows();
The reason that your call to num_rows generated an error is that your query had an error, and query() returned false instead of a valid result resource. Because it's a fatal error to try to call a method on a false value, you should always check the return value of query() before using it. Example:
if (!($result = $link->query($sql))) {
die($link->error);
}
Problems with your query:
You create a database named users and make that the default database, then you run a SELECT query from a table named users. There would be no tables in a database you have just created. In SQL, we use SELECT against tables, not databases (these are two different things, analogous to files contained in a directory on a filesystem).
You don't quote the string arguments in your SQL statement. For example, this SQL would be an error:
SELECT id FROM users WHERE email = bill#example.com AND username = bill
It should be this instead:
SELECT id FROM users WHERE email = 'bill#example.com' AND username = 'bill'
I know the quotes get confusing, because you have PHP string quotes and then SQL string quotes, but here are several ways of accomplishing it:
$sql='SELECT id FROM users WHERE email = \''.$useremail.'\' AND username = \''.$username.'\'';
$sql="SELECT id FROM users WHERE email = '".$useremail."' AND username = '".$username."'";
$sql="SELECT id FROM users WHERE email = '{$useremail}' AND username = '{$username}'";
I'm not sure if you have protected your PHP variables appropriately. You must never interpolate PHP variables into SQL strings unless you have escaped the content of the variables.
$useremail_esc = $link->real_escape_string($useremail);
$username_esc = $link->real_escape_string($username);
$sql="SELECT id FROM users WHERE email = '{$useremail_esc}' AND username = '{$username_esc}'";
But it would be better to use prepared statements with parameter placeholders. This is easier to use than escaping variables, and it's more reliable. Here's an example:
$sql="SELECT id FROM users WHERE email = ? AND username = ?";
$stmt = $link->prepare($sql);
$stmt->bind_param("ss", $useremail, $username);
$stmt->execute();
$result = $stmt->get_result();
Notice that you don't use escaping when you use parameters, and you don't put SQL quotes around the ? placeholders.

Message after sending mail asp.net

string Emails = "";
foreach (GridViewRow gr in gvregview.Rows)
{
CheckBox chk = (CheckBox)gr.FindControl("Checked");
Label ID = (Label)gr.FindControl("lblEmail");
Label lbl = (Label)gr.FindControl("lblPass");
Label Lblmrno = (Label)gr.FindControl("Lblmrno");
if (chk.Checked == true)
{
SendMail(ID.Text, lbl.Text);
//lblmsg.Text = "Mail Sent to "+Lblmrno.Text;
Response.BufferOutput = true;
puposalda.MailSentResponse = Lblmrno.Text;
//Response.Write("Mail to sent to" + Lblmrno.Text);
System.Threading.Thread.Sleep(500);
}
}
Hi Everybody, i want to send mail to all selected users in gridview and display Message 'Mail sent to the user UserName' for each user. Mail is sent successfully but only last user name is displaying. How to do that. Response.write is working but it is displaying message on the top. But i want to display message at specific location.
Thanks
Thanks
lblmsg.Text += "Mail Sent to "+Lblmrno.Text+", ";
in that case you ADD the text, not replace it.
I want to replace text not append Text. When mail to the first user has been sent successfully. Then message should display on the page. then same for other users.