I noticed the following bug:
When I add an address to a customer using the admin backend, or if I change an address and i save the customer, the Magento Costumer AccountController sends a standard email to the updated customer. The email template used is the template for the customer event "confirmed". This always happens when I update the customer.
Had someone the same problem or a solution for this? I can't understand why magento sends an email for this event...
Class: Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
Methode: saveAction()
Solution: It's a core bug from older versions. The condition for sending a mail after saving a customer uses isset($sendPassToEmail). But if you notice, the sendPassToEmail variable is always set and has the values true or false. Because of the isset() the condition is always true and an email will be send every time a customer is saved.
...
$sendPassToEmail = false;
// force new customer active
if ($isNewCustomer) {
$customer->setPassword($data['account']['password']);
$customer->setForceConfirmed(true);
if ($customer->getPassword() == 'auto') {
$sendPassToEmail = true;
$customer->setPassword($customer->generatePassword());
}
}
Mage::dispatchEvent('adminhtml_customer_prepare_save', array(
'customer' => $customer,
'request' => $this->getRequest()
));
$customer->save();
// send welcome email
if ($customer->getWebsiteId() && (!empty($data['account']['sendemail']) || isset($sendPassToEmail))) {
$storeId = $customer->getSendemailStoreId();
if ($isNewCustomer) {
$customer->sendNewAccountEmail('registered', '', $storeId);
}
// confirm not confirmed customer
else if ((!$customer->getConfirmation())) {
$customer->sendNewAccountEmail('confirmed', '', $storeId);
}
}
Related
Context I am using: office-js (retrieve rest ID of message item), java backend (using GraphClient to get the immutable ID, subscription webhook endpoint)
When I get the rest itemId of the draft item via office-js like this:
Office.context.mailbox.item.saveAsync((asyncResult) => {
if (asyncResult.error) {
//hadle
} else {
resolve(
Office.context.mailbox.convertToRestId
(
asyncResult.value,
Office.MailboxEnums.RestVersion.v1_0
)
);
}
});
I send it to the backend where I translate it to Immutable ID, via GraphClient, that I save.
Once I get a notification on my subscription endpoint (I change and save the subject of the message draft
in outlook), it is successfully paired.
Problem is when I send the draft from outlook. I get notification to the subscription enpoint, but it has a different immutable ID. I create subscriptions with Prefer header like this:
Subscription subscription = new Subscription();
subscription.changeType = "updated";
subscription.notificationUrl = notificationUrl;
subscription.resource = resource;
subscription.expirationDateTime = OffsetDateTime.now().plusDays(2);
subscription.clientState = secret;
subscription.latestSupportedTlsVersion = "v1_2";
SubscriptionCollectionRequest request = graphServiceClient.subscriptions().buildRequest();
if(request != null) {
request.addHeader("Prefer", "IdType=\"ImmutableId\"");
request.post(subscription);
} else {
Is there anything I am doing wrong? Draft is move to the "Sent items" folder, which should not change immutable ID (https://learn.microsoft.com/en-us/graph/outlook-immutable-id).
Ids looks like this AAkALgAAA.........yACqAC-EWg0AC.......7B4s_RdwAA....TwAA I suppose they are correct. Just last section after underscore changes on draft sent.
Not surprising at all - it is a physically different message. Just the way Exchange works - sent/unsent flag cannot be flipped after the message is saved, so a new message is created in the Sent Items folder.
get error whe subscription Newsletter. How can fix?
Here is the problem and the solution to this bug:
When we enter an new email address (one that is not connected to an extisting subscriber), the subscriber object ($this) has no id ($this->getId(); // null) yet in Magento\Newsletter\Model\Subscriber::subscribe.
The verification email is sent out before the subscriber is saved, thus the subscriber id is missing from the verification link. The link does not do anything when you click on it because the verification method in Magento\Newsletter\Controller\Subscriber\Confirm::execute rejects the link because of the missing id.
You can easily mend the problem by calling $this->save() before calling $this->sendConfirmationRequestEmail();
try {
$this->save();
if($isConfirmNeed === true && $isOwnSubscribes === false)
{
$this->sendConfirmationRequestEmail();
} else {
$this->sendConfirmationSuccessEmail();
}
return $this->getStatus();
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
I simply moved the ''save'''- call a few lines up. sendConfirmationRequestEmail and sendConfirmationSuccessEmail do not seem to alter the $thisobject, so this is a valid change that does not break anything else.
I just changed the "Disable Email Communications" to yes in Magento 2 ( Stores > Configuration > Advanced > System > Mail Sending Settings > Disable Email Communications).
I am totally new to PHP and I am just trying to block spam in my forms. I have
figured out how to do a honeypot (url field) with the following code that
blocks 90% of the spam - but this one irritating emailer gets through
(let's call them redacted#example.com). I would like to write one line of
code in my form that just says if the email field is filled out with the text
'redacted#example.com', then don't pass the form through. Is there anyone who can help me do this?
// if the url field is empty
// if(isset($_POST['url']) && $_POST['url'] == ''){
// then send the form to your email
// mail( 'myemail#me.com', 'Contact Form', print_r($_POST,true) );
// }
// otherwise, let the spammer think that they got their message through
Use this code
if(isset($_POST['url']) && $_POST['url'] == '') {
if ($_POST['email'] != 'dukang2004#yahoo.com') {
// then send the form to your email
mail( 'myemail#me.com', 'Contact Form', print_r($_POST,true) );
}
}
I want to automate the creation of invoice and email in Magento. Invoice creation seems to work but I am having getting the email part working...
Mage::app();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderid);
try
{
if(!$order->canInvoice()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
}
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
if (!$invoice->getTotalQty()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
}
catch (Mage_Core_Exception $e) {
}
}
I know my reaction is kinda late but for others who find this page:
You need to add the code for sending the email.
Do this after the register line:
$invoice->register();
$invoice->getOrder()->setCustomerNoteNotify(true);
$invoice->getOrder()->setIsInProcess(true);
$invoice->sendEmail();
setCustomerNoteNotify is used to say if the customer has to get the email.
setIsInProcess will change the order state to processing
I'm new to working with Codeigniter and need to set a form validation rule and custom validation message for checking if the email address exists in the database that is submitted in a forgot password form. If the email address exists it sends an email, if it doesn't it should reload the form, set the field value to what the user entered and provide an error that the email address doesn't exist.
I've got the following in the controller...
public function forgot_password()
{
$this->form_validation->set_rules('email_address','Email Address','trim|required|valid_email');
if($this->form_validation->run() == FALSE)
{
$this->forgot_password_form();
}
else
{
$this->load->model('membership_model');
if($query = $this->membership_model->val_forgot_password())
{
$data['main_content'] = 'forgot_password_sent';
$this->load->view('includes/template', $data);
}
else
{
$this->form_validation->set_message('email_address','The email address you provided does not exist.');
$this->forgot_password_form();
}
}
}
and in the model...
public function val_forgot_password()
{
$this->db->where('email_address', $this->input->post('email_address'));
$query = $this->db->get($this->members);
if($query->num_rows == 1)
{
return true;
}
else
{
return false;
}
}
and the form is...
<?php
echo form_open('login/forgot_password');
echo "Email Address: " . form_input('email_address', set_value('email_address', ''));
echo br(2);
echo form_submit('submit','Send Email');
echo form_close();
echo br(1);
echo validation_errors('<p>Error: ');
?>
When the form is submitted with a valid email address it correctly goes to the success page but if the email address doesn't exist, it appears to reload the form but does not give an error.
Help pls! :D
You should use a callback to check the email exists. So your controller would be something like...
public function forgot_password()
{
$this->form_validation->set_rules('email_address','Email Address','trim|required|valid_email|callback__check_email_exists');
if($this->form_validation->run() == FALSE)
{
// VALIDATION ERRORS, SHOW VIEWS
}
else
{
// ALL IS GOOD, UPDATE EMAIL, AND REDIRECT TO CURRENT URL
}
}
And your callback (still in your controller) would be something like...
public function _check_email_exists($email)
{
// LOAD AND USE YOUR MODEL TO CHECK EMAIL EXISTS HERE
if ( ! $email_exists )
{
$this->form_validation->set_message('email_address', 'That email address don\'t exist, sucka!');
return FALSE;
}
else
{
return TRUE;
}
}
All this is spelled out in the excellent CI docs here, and I would recommend sticking to the CI conventions if you are new to it.
http://codeigniter.com/user_guide/libraries/form_validation.html
EDIT: There is also another problem i was facing while doing this in codeigniter3. You have to named the message field name to the callback. So instead of $this->form_validation->set_message('email_address', 'That email address don\'t exist, sucka!');
This should be
$this->form_validation->set_message('_check_email_exists', 'That email address don\'t exist, sucka!');
You should extend MY_Form_validation, this way your function can be used on any form, not just those that reside in your controller.