I'm running Moodle, and have a teacher who receives a notification email anytime a student enrolls in a course (via PayPal enrollment).
The email contents come from lang/en/enrol.php:
$string['enrolmentnewuser'] = '{$a->user} has enrolled in course "{$a->course}";
What I'm trying to do is include the student's email address in this, for the teacher to reference.
Here's what I've tried:
$string['enrolmentnewuser'] = '{$a->user} has enrolled in course "{$a->course}". Student\'s email address: {$a->email}';
To make this $a->email variable available, I went into the function that gets the email contents: enrol/flatfile/lib.php::process_records()
Inside process_records(), I added the following:
$a->email = $user->email;
I put this directly after these lines:
$a = new stdClass();
$a->course = format_string($course->fullname, true, array('context' => $context));
$a->user = fullname($user);
and before this line, which gets the email contents:
$eventdata->fullmessage = get_string('enrolmentnewuser', 'enrol', $a);
I would think that the $a object would now contain my new 'email' property, which would be accessible in the 'enrolmentnewuser' string.
I've cleared the cache after my updates.
Unfortunately, this is the email the teacher is now receiving:
Student has enrolled in course "Test Course". Student's email address: {$a->email}
It looks like the $a->email is not swapping the actual property into the message. For the life of me, I haven't been able to figure out why it's not working. It's been difficult to debug, as I have to keep enrolling and un-enrolling in the test course which is frustrating.
Does anyone have any insight into why this is printing the $a->email property name literally, instead of the actual property?
In your case, you need to add the below line to enrol/paypal/ipn.php file also.
$a->email = $user->email;
put this directly after these lines:
$a->course = format_string($course->fullname, true, array('context' => $coursecontext));
$a->user = fullname($user);
Related
I am working on Yii and I need to send a confirmation email one sign up. The content shows the email as abc%40#example.com
the email is directly called from the database and added to the mail function
I am not sure how this can be fixed
$activation_url = $this->createAbsoluteUrl('/user/activation/activation',array("activkey" => $registerform->activkey, "email" => $registerform->email));
the above code is the sample
Any help is appreciated
Apologies
the result is shown like this abc%40example.com and not abc%40#example.com
Try this:
$activation_url = $this->createAbsoluteUrl('/user/activation/activation',array("activkey" => $registerform->activkey, "email" => urldecode($registerform->email)));
I'm using this lib to send two different messages with different collapse keys, but on my device I'm receiving the first and then the second is coming over the first.
I would like to have the two separately in the Android notification header on device.
For the record I'm using this Phonegap plugin to receive the push notification.
Here is my code:
$gcmApiKey = 'api key here';
$deviceRegistrationId = 'device regid here';
$numberOfRetryAttempts = 5;
$collapseKey = '1';
$payloadData = ['title' => 'First Message Title', 'message' => 'First message'];
$sender = new Sender($gcmApiKey);
$message = new Message($collapseKey, $payloadData);
$result = $sender->send($message, $deviceRegistrationId, $numberOfRetryAttempts);
// Sending Second message
$collapseKey = '2';
$payloadData = ['title' => 'Second Message Title', 'message' => 'Second Message'];
$sender = new Sender($gcmApiKey);
$message = new Message($collapseKey, $payloadData);
$result = $sender->send($message, $deviceRegistrationId, $numberOfRetryAttempts);
If I understand you right, your problem is that the first notification is replaced by the second after it was shown.
If that is the case, your mistake is not on the PHP-side here, but in your Java-code.
If you show a notification you call this method:
NotificationManager.notify(int id, Notification notification)
Most likely, you are setting the id parameter to the same value each time you call this method.
The effect of the id is that the system will only show one notification with the same ID - the newest. A typical use-case to use the same id as before would be to update a previous notification.
If you want to display multiple notifications, you need to set a different id each time. You could use a random number or better yet use a previously defined ID of your content.
The GCM collapse key has a different effect:
When you define a collapse key, when multiple messages are queued up in the GCM servers for the same user, only the last one with any given collapse key is delivered.
That means, for example, if your phone was off, you would only receive one message with the same collapse key. It doesn't do anything if your phone receives the first notification before you send the second.
To set it with your PhoneGap plugin
The plugin has a really messy documentation but if we look into the source code, we'll find this undocumented feature:
int notId = 0;
try {
notId = Integer.parseInt(extras.getString("notId"));
}
mNotificationManager.notify((String) appName, notId, mBuilder.build());
That means, if you change your payload to, for example:
$payloadData = ['title' => 'First Message Title', 'message' => 'First message', 'notId' => mt_rand()];
your notifications won't replace each other.
I have a database of 'user comments' that holds the comment, the userId, true/false for if they want to be emailed.
My issue is that if a user comments on a post 5 times, they are in that database 5 times and thus, they get 5 of the same emails. Here is my setup:
Find users in the database that want to be emailed about this comment
$ab = $modx->newQuery('Comments');
$ab->leftJoin('modUserProfile','Profile',array('Profile.internalKey = Comments.author'));
$ab->leftJoin('Bulletin','Bulletin',array('Bulletin.id = Comments.bulletin_id'));
$ab->where(array('Comments.bulletin_id' => $bullId));
$ab->where(array('Comments.email' => 1));
$ab->select(array('Comments.*','Profile.fullname as fullname' , 'Profile.email as email' , 'Bulletin.title as title'));
$emailList = $modx->getCollection('Comments',$ab);
Now, email them
foreach ($emailList as $e){
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->address('to',$e->email);
$modx->mail->set(modMail::MAIL_BODY,$message);
$modx->mail->set(modMail::MAIL_SUBJECT,'A new comment has been posted!');}
What should I use to email the users so that they only get 1 email regardless of the amount of comments they have made? Please let me know if the above is not clear enough. Thank you!!
I think you can add a groupby....
$ab->groupby('email');
after your select
I have created a 'Companyname' attribute which gets added up in my Customer's Account information and is a required field.
It gets filled up on registration, form and edit pages fine and gets displayed on Customer's Grid in the back-end too.
However I am not able to display the Company name in any of my order email templates.
I believe this is because there is neither any column called 'companyname' in my order tables nor do I have any custom variable which I can pass to order/invoice/shipment templates to display Company name right next to the line after Customer's name.
Can any one point out the file where I can create this custom variable containing my custom 'companyname' attribute and pass it to all types of sales email templates
Thanks
After a little bit of searching I found the right file to make the changes. Since I already had 'companyname' as one of my attributes I retrieved the value of this field and passed it as a param in the following function
app/code/core/Mage/Sales/Model/Order.php
public function sendNewOrderEmail()
{
/*Existing Code*/
if ($this->getCustomerIsGuest()) {
$templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
$customerId = Mage::getModel('customer/customer')->load($this->getCustomerId());
$companyname = $customerId->getCompanyname();
$customerName = $this->getBillingAddress()->getName();
} else {
$templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
$customerId = Mage::getModel('customer/customer')->load($this->getCustomerId());
$companyname = $customerId->getCompanyname();
$customerName = $this->getCustomerName();
}
/*Existing Code*/
$mailer->setTemplateParams(array(
'order' => $this,
'billing' => $this->getBillingAddress(),
'payment_html' => $paymentBlockHtml,
'companyname' => $companyname
));
/*Rest of the code remains the same*/
}
After making this change. I edited my Transactional Email to include this param. Since I wanted to display inside Shipping Address, I placed my variable just before this line in
System > Transactional Emails > New Order Email
{{ var companyname }}
{{var order.getShippingAddress.format('html')}}
If your companyname is getting saved as a part of Customer Information then this would get displayed in your Order Email in 'Shipping Address' Information right at the Start.
You can do the same for Invoice and Shipment Emails.
Hope this helps someone !!! :-)
I have this method:
public function activation_code()
{ //activation code sent into db
$activation_code = random_string('alnum', 32);
return $activation_code;
}
What I'm trying to do is provide this with the post data that gets sent to my database but also provide a copy of that same activation code so I can concatenate it with the "click here to confirm email" url that is in my confirmation email that is sent to users upon registration.
How can I do this? I can't provide the method because if I do the database code and the email URL code will be different so user wouldn't be able to match them and confirm their email address.
I've tried many other ways such as providing the method in one place e.g.
public function create()
{ //get post data and insert into db
$dbcolumn->group_id = 2; //group 1 for admin group 2 for member
$dbcolumn->first_name = $this->input->post('first_name');
$dbcolumn->last_name = $this->input->post('last_name');
$dbcolumn->email = $this->input->post('email');
$dbcolumn->password = $this->hashed();
$dbcolumn->birthday = $this->input->post('year') .
'-' . $this->input->post('month') . '-' . $this->input->post('day');
$dbcolumn->sex = $this->input->post('sex');
$dbcolumn->activation_code = $this->activation_code();
// date and time user joined the website
$dbcolumn->created_on = date('Y-m-d H:i:s', now());
$this->db->insert('users', $dbcolumn);
}
If you look at the dbcolumn->activation code line you'll see what I've done. That works and the code is stored in the database. If I provide the same "$this->activation_code() method to the email that's sent the codes will obviously be different.
public function send_confirmation_email()
{ //receives variable from create method
$this->load->library('email');
$this->email->from('wengerarsen#gmail.com', 'my site');
$this->email->to($this->input->post('email'));
$this->email->subject('my site - Activate your account');
//copy of activation code returned from create method
$this->email->message('We\'re back, please click the link to activate your account ' . anchor('http://mysite.com/activation/' . $this->activation_code(), 'Activate my account'));
$this->email->send();
}
As you can see I have the same method $activation_code() pulled into my send confirmation email method. This will just generate a whole new code meaning I won't be able to match the database activation code and the URI segment code in the users email.
I have tried to make the variable in the return public and call it in the send confirmaton email method but it doesn't work. The code ends up missing from he end of the URL in the email.
I've tried so many different ways and nothings working.
Maybe I'm missing something here?
Advice, examples etc will be much appreciated.
Every time you're calling activation_code() you're going to be creating a new code, because you're only storing it in the scope of that function.
A better idea would be to store it as an object property, like follows:
public var $_activation_code = null;
public function activation_code() {
if (is_null($this->_activation_code)) {
$this->_activation_code = random_string('alnum', 32);
}
return $this->_activation_code;
}
This will create the code if it hasn't already been done so for this object, or will simply return the current code if the method has been called more than once, meaning the code will be consistent across the object.