1

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('[email protected]', $storeScope)
                ->addTo('[email protected]', $storeScope)
                ->setReplyTo('[email protected]')
                ->getTransport();
        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

2
  • 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

2

You have to replace ->setFrom('[email protected]', $storeScope) to ->setFrom('[email protected]') 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))
3
  • Still issue, By changing it
    – Jackson
    Sep 6, 2016 at 10:12
  • you can change inside ->addTo('[email protected]', $storeScope) to ->addTo('[email protected]') 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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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