Jump to content

Mail::Send issue Trying to get property of non-object


apomed

Recommended Posts

Hi,

 

I try to send email useing Mail::Send function but when I did this I get in my php error log 

 

PHP Notice: Trying to get property of non-object

 

Version : 1.6.1.4

 

MyCode is:

 

public function __construct()	{//print_r($_REQUEST);die();

		if (empty($_REQUEST['email']) || !Validate::isEmail($_REQUEST['email']))
			echo json_encode(array("message" => $this->error = $this->l('Invalid email address.'),"code" => 0));
		/* Subscription */
		else if ($_REQUEST['action'] == '0')
		{
			$register_status = $this->isNewsletterRegistered($_REQUEST['email']);
			if ($register_status > 0)
				echo json_encode(array("message" => $this->error = $this->l('This email address is already registered.'),"code" => 0));
		
			$email = pSQL($_REQUEST['email']);
			if (!$this->isRegistered($register_status))
			{
				if (Configuration::get('NW_VERIFICATION_EMAIL'))
				{
					// create an unactive entry in the newsletter database
					if ($register_status == $this->GUEST_NOT_REGISTERED)
						$this->registerGuest($email, false);
		
					if (!$token = $this->getToken($email, $register_status))
						return json_encode(array("message" => $this->error = $this->l('An error occurred during the subscription process.'),"code" => 0));
		
					$this->sendVerificationEmail($email, $token);
		
					echo json_encode(array("message" => $this->error = $this->l('A verification email has been sent. Please check your inbox.'),"code" => 0));
				} else {	
					if ($this->n register($email, $register_status)) 	
						$this->valid = $this->l('You have successfully subscribed to this newsletter.');
					else
						return $this->error = $this->l('An error occurred during the subscription process.');

					if ($code = Configuration::get('NW_VOUCHER_CODE')) 
						$this->sendVoucher($email, $code);
				

					if (Configuration::get('NW_CONFIRMATION_EMAIL'))
						$this->sendConfirmationEmail($email);

					echo json_encode(array("message" => $this->error = $this->l('Your email was registered. Thank You!'),"code" => 1));
					die();

					}
				}
			}
		}
protected function sendVoucher($email, $code)
{

return Mail::Send($this->context->language->id, 'newsletter_voucher', Mail::l('Newsletter voucher', $this->context->language->id), array('{discount}' => $code), $email, null, null, null, null, null, dirname(__FILE__).'/mails/', false, $this->context->shop->id);
}

 

The filename is subscribe and it is called by AJAX

 

Edited by apomed (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...