magento newsletter keeps returning an error even after email is saved - magento

There was a problem with the subscription.
this is the message I get after I enter an email. When I go to the admin panel the email is added.
I would like it NOT to display this message. any suggestions please

The only place in Magento that error string occurs is in the following try/catch block
#File: app/code/core/Mage/Newsletter/controllers/SubscriberController.php
try {
//...snip!...
}
catch (Mage_Core_Exception $e) {
$session->addException($e, $this->__('There was a problem with the subscription: %s', $e->getMessage()));
}
catch (Exception $e) {
$session->addException($e, $this->__('There was a problem with the subscription.'));
}
Since you reported the error message as "There was a problem with the subscription.", that means the newsletter subscription code is throwing some sore of PHP exception, caught by the catch (Exception $e) { block. Magento does not output the messages from PHP exceptions. If I was in your position I'd temporarily change the exception handling code to include the error message
$session->addException($e, $this->__('There was a problem with the subscription. ' . $e->getMessage()));
This will let you track down the PHP error that's triggering your error message.
Per the comment below, the only place the "Cannot set standard header from addHeader()" exception error exists is
#File: lib/Zend/Mail.php
$prohibit = array('to', 'cc', 'bcc', 'from', 'subject',
'reply-to', 'return-path',
'date', 'message-id',
);
if (in_array(strtolower($name), $prohibit)) {
/**
* #see Zend_Mail_Exception
*/
#require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('Cannot set standard header from addHeader()');
}
$value = $this->_filterOther($value);
$value = $this->_encodeHeader($value);
$this->_storeHeader($name, $value, $append);
return $this;
My guess is somewhere in your system someone's added some custom code that tries to set one of the standard email headers via the addHeader method.

Related

Laravel package whoops exception

In my Laravel package I have this code:
try {
$var_msg = "Exception example";
throw new InvalidNameException($var_msg);
}
catch (InvalidNameException $e) {
abort(403, $e->getMessage());
//report($e);Exception Log
}
The error is displayed as html error page. But, I'd like to report the error as an whoops error.
Take this code as reference.
$whoops = new \Whoops\Run();
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
// Set Whoops as the default error and exception handler used by PHP:
$whoops->register();
throw new \RuntimeException("Oopsie!");

Unable to catch error in laravel using try catch

I wrote a code to try and catch error.
I want that if the error occurs then laravel continues to the next one and i write the error in the error file as shown here.
Laravel's black page of error pops up which shows "ErrorException (E_WARNING) followed by the whole error on the left page and the programme is abruptly stopped.
Is there a way to skip the error notification which brings my whole code to a stop.
My attempt at coding to catch the error is here:
try {
$jsondata_car = (file_get_contents($urltofind_car));
} catch (Exception $e) {
$errorfile = fopen("errors", 'a');
fwrite($errorfile, $e - > getmessage().
"\n");
$failed_car = 9999999;
report($e);
return false;
}
Am I missing out something?
The error I get is here
file_get_contents(): failed to open stream:
HTTP request failed! HTTP/1.1 400 Bad Request
The error is shown on the line
$jsondata_car = (file_get_contents($urltofind_car));
The solution is here
Exception is used which should have contained a namespace.
The problem is that this does not throw up an error even though I had not written
Use Exception;
at the beginning.
As suggested by #simon R I made the rectification and it worked.
It is most likely still throwing the error because you haven't imported the Exception class
Ensure you either add
Use Exception;
to your class.
Alternative update your code to namespace it;
try {
$jsondata_car = (file_get_contents($urltofind_car));
} catch (\Exception $e) {
$errorfile = fopen("errors", 'a');
fwrite($errorfile, $e - > getmessage().
"\n");
$failed_car = 9999999;
report($e);
return false;
}

magento add to wishlist message in product details page

I want to show Wishlist Success Message in the product details page. I have change the redirection part. Now my page is redirecting to same page after added the product to wishlist. But I need to Show the message in same page. Kindly Help.. Thanks in advance. P.S.- I don't want to use ajax add to wishlist functionality.
The Magento Session models i.e. core/session, customer/session and catalog/session etc.
To add a message you can use "app\code\core\Mage\Wishlist\controllers\IndexController.php":
Action : addAction()
Find :
$session->addSuccess($message);
below write this code:
Mage::getSingleton('catalog/session')->addSuccess($message);
Then add error message :
Find :
catch (Mage_Core_Exception $e) {
$session->addError($this->__('An error occurred while adding item to wishlist: %s', $e->getMessage()));
}
catch (Exception $e) {
$session->addError($this->__('An error occurred while adding item to wishlist.'));
}
replace with below code :
catch (Mage_Core_Exception $e) {
$session->addError($this->__('An error occurred while adding item to wishlist: %s', $e->getMessage()));
$error_msg = $this->__('An error occurred while adding item to wishlist: %s', $e->getMessage());
Mage::getSingleton('catalog/session')->addError($error_msg);
} catch (Exception $e) {
$session->addError($this->__('An error occurred while adding item to wishlist.'));
Mage::getSingleton('catalog/session')->addError('An error occurred while adding item to wishlist.');
}
If "catalog/session" is not working please try "core/session".

Programmatically send SMS to customers when a order delivery status is changed

I want to send a notification SMS to customers when I change order delivery status from admin panel, purchased SMS service from India
You need to check the order status for changing - there is no event for this so you need:
Event: sales_order_load_after to get the order status after load
Method:
public function fetchOrderStatus(Varien_Event_Observer $observer){
try{
if (!Mage::registry('cartware_order_status')){
Mage::register('cartware_order_status', $observer->getOrder()->getStatus());
}
}
catch (Exception $e){
Mage::logException("UNEXPECTED PROBLEM WIH REGISTER");
Mage::logException($e);
}
return;
}
Event: sales_order_save_after to get the order status after save:
Method:
public function checkOrderStatus(Varien_Event_Observer $observer){
try{
if(!Mage::registry('cartware_order_status')){
return;
}else{
$orderStatus = Mage::registry('cartware_order_status');
}
}
catch (Exception $e){
Mage::logException("UNEXPECTED PROBLEM WIH REGISTRY");
Mage::logException($e);
}
if ($orderStatus != $observer->getOrder()->getStatus() &&
$observer->getOrder()->getStatus() == [STATUS YOU WANT TO REACT IF CHANGE TO]){
sendYourSmsMethod();
}
}
Good luck!

Swift Mailer : Address in mailbox given [] does not comply with RFC 2822, 3.6.2

I have a little problem here, when I try to send an email using swiftmailer, I got an error.
Here's my code:
<?php
session_start();
include("config.php");
$dir = dirname(__FILE__);
$session = $_SESSION[serialize];
// Load the SwiftMailer files
require_once($dir.'/swift/swift_required.php');
$hold = 'TIDAK';
// Kondisi - Kondisi yang ada
if($_GET[phase]=='confirm'){
$to = "test#127.0.0.1";
$kalimat = "Invoice Dengan nomor ".$_GET[nosc]." Telah di confirm, mohon di cek di sistem";
$kalimat2 = "Berikut terlampir data Invoice Customer , mohon di pastikan.";
$title = "CONFIRMATION NOTIFICATION";
}
// Convert string dlu
$mailer = new Swift_Mailer(new Swift_MailTransport()); // Create new instance of SwiftMailer
$message = Swift_Message::newInstance()
->setSubject($title) // Message subject
->setTo(array($to)) // Array of people to send to
->setBcc(array($bcc)) // Bcc:
->setFrom(array($_SESSION[mailadmin] => $_SESSION[namauser].''.store('namasite'))) // From:
->setBody($kalimat, 'text/html'); // Attach that HTML message from earlier
// Send the email, and show user message
if($hold<>'YA'){
if ($mailer->send($message)){
echo json_encode(array('success'=>true));
} else {
echo json_encode(array('success'=>false));
}
}
?>
And then when I try to post the data to this file through jquery I got an error, this error I got from firebug.
<br />
<b>Fatal error</b>: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [] does not comply with RFC 2822, 3.6.2.' in C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime\Headers\MailboxHeader.php:319
Stack trace:
#0 C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime\Headers\MailboxHeader.php(249): Swift_Mime_Headers_MailboxHeader->_assertValidAddress(NULL)
#1 C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime\Headers\MailboxHeader.php(107): Swift_Mime_Headers_MailboxHeader->normalizeMailboxes(Array)
#2 C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime\Headers\MailboxHeader.php(71): Swift_Mime_Headers_MailboxHeader->setNameAddresses(Array)
#3 C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime\SimpleHeaderFactory.php(74): Swift_Mime_Headers_MailboxHeader->setFieldBodyModel(Array)
#4 C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime\SimpleHeaderSet.php(87): Swift_Mime_SimpleHeaderFactory->createMailboxHeader('Bcc', Array)
#5 C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime in <b>C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime\Headers\MailboxHeader.php</b> on line <b>319</b><br />
So guys, anybody can help me here? I really doesn't know what happening here.
It's better if you use a try/catch around the send instruction:
try {
if ($mailer->send($message)){
...
}
} catch (Exception $e) {
$log_error->write_error($e->getMessage() . ';');
}
Or if you validate the email before sending it:
if(!Swift_Validate::email($email)){ //if email is not valid
//do something, skip them or log them
$log_error->log($email);
}
Please make sure there is no white space before or after the email address given.

Resources