Jump to content

Capture logged in users email address in code


Recommended Posts

I have created a simple contact module that emails the store admin when a button is pressed with the logged in users name, last name and email address, along with a message asking the admin to contact them.

 

Everything works perfectly, except one thing..I cannot seem to capture the logged in users telephone number and include it in the email. This is the email code:

 

<?php
 
 
class recurring_psdisplayModuleFrontController extends ModuleFrontController
{
 
   public function postProcess()
 
 {
 
 Mail::Send((int)(Configuration::get('PS_LANG_DEFAULT')), // defaut language id
        'recurring', // email template file to be use
        'Recurring Order Request', // email subject
        array(
'{firstname}' => $this->context->customer->firstname, // sender first name
'{lastname}' => $this->context->customer->lastname, // sender last name
        '{email}' => $this->context->customer->email, // sender email address
'{delivery_phone}' => ,  // sender telephone
        ), 
        '[email protected]', // receiver email address 
        NULL, NULL, NULL);
 }
 
 
public function initContent()
   {
      // Prepare Vars
$this->display_column_left = false;
$this->display_column_right = false;  
parent::initContent();
    $this->setTemplate('success_display.tpl');
 
 
   }
}
 
Does anyone know how to capture the users telephone number, and display it in the email? Any help would be appreciated. I have tried many methods and all of them fail. I have also tried print_r and this can extract the users details, but again, it will not copy and insert into the email. 
 
When the email is received, the customer telephone field is blank, no matter what I try.
 
Many thanks,
 
Chris
 
Link to comment
Share on other sites

The phone number is not in the context, you need get it manually, according to your code, should work with this modification...

<?php

class recurring_psdisplayModuleFrontController extends ModuleFrontController
{
	public function postProcess()
	{
		$address = new Address($this->context->cart->id_address_delivery); // If you need information from the invoice address, then change "id_address_delivery" for "id_address_invoice"
		Mail::Send((int) (Configuration::get('PS_LANG_DEFAULT')), // defaut language id
			'recurring', // email template file to be use
			'Recurring Order Request', // email subject
			array(
				'{firstname}'      => $this->context->customer->firstname, // sender first name
				'{lastname}'       => $this->context->customer->lastname, // sender last name
				'{email}'          => $this->context->customer->email, // sender email address
				'{delivery_phone}' => $address->phone, // if you need the mobile phone, then change this to: $address->phone_mobile
			),
			'[email protected]', // receiver email address
			null, null, null);
	}

	public function initContent()
	{
		// Prepare Vars
		$this->display_column_left  = false;
		$this->display_column_right = false;
		parent::initContent();
		$this->setTemplate('success_display.tpl');

	}
}
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...