Using Magento 2 Version 2.1.0 on WAMP Windows 10

I'm using https://github.com/magepal/magento2-gmailsmtpapp

In magento Admin, then goto Stores -> Configuration -> Advanced -> System -> Gmail/Google Apps SMTP Pro. I have configured things

  • Authentication method: LOGIN
  • SSL type: SSL (Gmail / Google Apps)
  • SMTP Host: smtp.gmail.com
  • Username: Gmail Account Username
  • Password: GmailAccount Password
  • Set Reply-to: Yes
  • Set Return-Path: Yes

I have below code in my Controller

 $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
        $transport = $this->_transportBuilder->setTemplateIdentifier(1)
                ->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => 1])
                ->setTemplateVars(['data' => $postObject])
                ->setFrom('XXXX@gmail.com', $storeScope)
                ->addTo('XXXX@gmail.com', $storeScope)
        echo $transport->sendMessage();

When i run this code, it gives below error

1 exception(s): Exception #0 (Magento\Framework\Exception\MailException): Invalid sender data

Now it's causing

Could Not Open Socket

  • Does the default contact us form work? Sep 6, 2016 at 11:20
  • @ankit ...i am getting same problems if you have solutions please paste here Feb 22, 2017 at 13:06

1 Answer 1


You have to replace ->setFrom('XXXX@gmail.com', $storeScope) to ->setFrom('XXXX@gmail.com') in above code, Becasue setFrom method is not supported two arguments.

Check core function for this, inside file, magento2/vendor/magento/framework/Mail/Template/TransportBuilder.php

public function setFrom($from)
        $result = $this->_senderResolver->resolve($from);
        $this->message->setFrom($result['email'], $result['name']);
        return $this;

if you want to pass storescope in your method, please refer core contact module mail functionality from here, magento2/vendor/magento/module-contact/Controller/Index/Post.php

->setFrom($this->scopeConfig->getValue(self::XML_PATH_EMAIL_SENDER, $storeScope))
  • Still issue, By changing it
    – Jackson
    Sep 6, 2016 at 10:12
  • you can change inside ->addTo('XXXX@gmail.com', $storeScope) to ->addTo('XXXX@gmail.com') remove var and check again Sep 6, 2016 at 10:24
  • Its' solved "Invalid Sender Data" Issue not getting "Could Not Open Socket" issue
    – Jackson
    Sep 7, 2016 at 1:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.