I want to send custom mail through smtp.For which I installed http://www.magentocommerce.com/magento-connect/aschroder-com-smtp-pro-email-free-and-easy-magento-emailing-for-smtp-gmail-or-google-apps-email.html.
Which works properly for every mail provided by magento as default.
Now since the admin is having mail Id of google apps , my custom mail is not received by admin.So for this reason I want to Integrate my controller with the sending mail function of ashrodder extension.
My Controller code:
$frm = 'mail#domainname.com';
$to = 'admin#domainname.com';
$subject = "UPDATE";
$mail = new Zend_Mail('utf-8');
$mail->setBodyHtml($message)
->setFrom($frm, 'Admin')
->addTo($to, 'Site Admin')
->setSubject($subject);
try {
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Mail sent successfully.');
}
catch(Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to send email.');
}
My question is simple : How should I pass [to,from,body] variable to any other model/controller ?
Please Help .Thanks in Advance
I think overriding the extensions controller would be the best solution.Check this link How to extend a controller
Related
I'm a beginner. I have a pin field in my user database. I want users to verify the pin before they can access there profile. how can I do this any logic?
in livewire components
public function verify (){
$user = User::select('id')->where('pin',$pin)->first();
Auth::loginUsingId($user->id);
return redirect()->intended('/user');
}
in my livewire blade I will call the verify method in the form will this work
laravel login using pincode :check the following code example may be you get the hint how to implement that, in this example code pin authentication is done using JWT and then user is allowed to access to those specific routes.
$user = User::find($uid);
try {
if (!$token = JWTAuth::fromUser($user)) {
return $this->onUnauthorized();
}
} catch (JWTException $e) {
return $this->onJwtGenerationError();
}
For somereason if you dont want to use the above JWT method you can use this one. i'm sharing the code for an example from by program which may help you
$user = User::select('id')->where('pin',$pin)->first();
Auth::loginUsingId($user->id);
return redirect()->intended('/user');
I'm struggling with a special little problem related to the redirect out of some Magento observer.
I wrote an extension and put an observer to the "checkout_submit_all_after" event, which works out just fine. My little extension automatically creates an invoice and sets the order status to processing, once the payment method is "Invoice". Unfortunately the redirect after submitting an order in the one page checkout doesn't work anymore. It always redirects to "checkout/cart" instead of "checkout/onepage/success".
Someone any ideas what I'm doing wrong?
Here's my code:
class Shostra_AutoInvoice_Model_Order_Observer
{
public function __construct()
{
}
public function auto_create_invoice($observer)
{
$order = $observer->getEvent()->getOrder();
if (!$order->hasInvoices()) {
$payment = $order->getPayment()->getMethodInstance()->getTitle();
Mage::log("payment method: " . $payment);
if($payment=="Rechnung"){
Mage::log("autocreating invoice");
$invoice = $order->prepareInvoice();
$invoice->register();
$invoice->pay();
$invoice->save();
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
Mage::log("invoice created and saved");
}
$this->addComment('Order automatically set to paid.');
} else {
$this->addComment('no invoices found.');
}
$response = $observer->getResponse();
$response->setRedirect(Mage::getUrl('checkout/onepage/success'));
Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
}
}
Thanks a lot!
Why don't you try sales_order_save_after event and try saving it, so no issues with redirection manually as Magento will take its own course,
you can refer to this link for more explanation
http://inchoo.net/magento/magento-orders/automatically-invoice-ship-complete-order-in-magento/
I want to send an email using codeigniter library to my newsletter members and I want to mention each members' Email address in email's content. For doing that, I used foreach loop to send the email one by one. The problem is that the code sends email to just one member ( the first member ) of my newsletter. I've checked my code which gets members from the database and it printed out all the members.
This is my model:
function send_news()
{
$subscribers = $this->get_subscriber_data();
foreach($subscribers as $subscriber)
{
$this->load->helper('typography');
//Format email content using an HTML file
$data['news_Title'] = $this->input->post('news_Title');
$HTML_Message = $this->load->view('admin/includes/newsletter_html_format', $data, true);
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from('newsletter#site.com', 'newsletter of site.com');
$this->email->to($subscriber->subscriber_Email);
$this->email->subject('newsletter of site.com');
$this->email->message($HTML_Message);
return $this->email->send();
}
}
and this is how I'm getting subscribers list:
function get_subscriber_data($options = array())
{
$query = $this->db->get('mg_newsletter');
if(isset($options['subscriber_Id']))
return $query->row(0);
return $query->result();
}
when I try to echo $subscriber->subscriber_Email it prints all the emails in the database one after another. but it does not send email to all of them. What am I doing wrong?!
use
$this->email->clear()
As codeignitor says:
Initializes all the email variables to an empty state. This function is intended for use if you run the email sending function in a loop, permitting the data to be reset between cycles.
foreach ($list as $name => $address)
{
$this->email->clear();
$this->email->to($address);
$this->email->from('your#example.com');
$this->email->subject('Here is your info '.$name);
$this->email->message('Hi '.$name.' Here is the info you requested.');
$this->email->send();
}
If you set the parameter to TRUE any attachments will be cleared as well. Then let us know
You are "return" -ing inside your loop, which exits the function.
Just send
You can keep the loading helper file and email configuration outside the loop and then remove the return from for loop, it will send to all subscribers one by one and then after loop finishes you can do the return statement.
I'd like the Password::remind method to respond with the token and not send email to the email address provided. Can I suppress/disable email?
help would be much appreciated.
I don't think you can, the best you can do is to make one yourself, using Laravel's way of doing it:
Create a new class:
<?php
use Illuminate\Auth\Reminders\DatabaseReminderRepository as DbRepository;
class Reminder {
public static function create($user)
{
$reminders = new DbRepository(DB::connection(), Config::get('auth.reminder.table'), Config::get('app.key'));
return $reminders->create( $user );
}
}
And use it
$user = User::find(2);
echo Reminder::create($user);
After that you can check your password_reminders table, you new token will be there:
select * from password_reminders;
How to add unsubscribe link in custom email notification i am sending an email through zend mail function i follow this function sending mail in magento in body part i want to add unsubscribe link how can we implement that?
In my e mail notification i am using this function.
public function sendMail()
{
$post = $this->getRequest()->getPost();
if ($post){
$random=rand(1234,2343);
$to_email = $this->getRequest()->getParam("email");
$to_name = 'Hello User';
$subject = ' Test Mail- CS';
$Body="Test Mail Code : ";
$sender_email = "sender#sender.com";
$sender_name = "sender name";
$mail = new Zend_Mail(); //class for mail
$mail->setBodyHtml($Body); //for sending message containing html code
$mail->setFrom($sender_email, $sender_name);
$mail->addTo($to_email, $to_name);
//$mail->addCc($cc, $ccname); //can set cc
//$mail->addBCc($bcc, $bccname); //can set bcc
$mail->setSubject($subject);
$msg ='';
try {
if($mail->send())
{
$msg = true;
}
}
catch(Exception $ex) {
$msg = false;
//die("Error sending mail to $to,$error_msg");
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($msg));
}
}
If you have a custom module use this code:
Mage::getModel('newsletter/subscriber')->loadByEmail($email)->getUnsubscriptionLink();
Explanation:
first part is the model for the subscriber.
If you want to see al the available methods within the model just use this code:
$myModel = Mage::getModel('newsletter/subscriber');
foreach (get_class_methods(get_class($myModel)) as $cMethod) {
echo '<li>' . $cMethod . '</li>';
}
the second part of the code loadByEmail($email) is to get 1 specific subscriber object. $email should be a string of the emailaddress.
The last part of the code is a selfexplaning method. It will generate a link to unsubscribe. This is a method that is given by Magento.
In my Magento version I get the following code by default when creating a new newsletter template:
Follow this link to unsubscribe <!-- This tag is for unsubscribe link -->{{var subscriber.getUnsubscriptionLink()}}
I expect it to work in any Magento version.
I am using Magento 1.9.
To add newsletter unsubscribe link in newsletter template here are following steps:
Override the core file
/app/code/core/Mage/Newsletter/Model/Subscriber.php
by copy in local directory
/app/code/local/Mage/Newsletter/Model/Subscriber.php
Open in editor to edit the code and seacrh the function sendConfirmationSuccessEmail()
replace the code
$email->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_TEMPLATE),
Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_IDENTITY),
$this->getEmail(),
$this->getName(),
array('subscriber'=>$this)
);
with this
$email->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_TEMPLATE),
Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_IDENTITY),
$this->getEmail(),
$this->getName(),
array('subscriber'=>$this, 'unsubscribe' =>$this->getUnsubscriptionLink())
);
and place this code in email template where you want to use unsubscribe link:
Unsubscribe here
That's it!
Hope this helps someone.