1

I will attached the phtml and php block code but client side mail does not send?

subscribe.phtml

<div class="block newsletter">
    <div class="title"><strong>Newsletter</strong></div>
    <div class="content">
        <form class="form subscribe"
            novalidate
            action="<?php /* @escapeNotVerified */ echo $block->getFormActionUrl() ?>"
            method="post"
            data-mage-init='{"validation": {"errorClass": "mage-error"}}'
            id="newsletter-validate-detail">
            <div class="field newsletter">
                <label class="label" for="newsletter"><span><?php /* @escapeNotVerified */ echo __('Sign Up for Our Newsletter:') ?></span></label>
                <div class="control">
                    <input name="email" type="email" id="newsletter"
                                placeholder="<?php /* @escapeNotVerified */ echo __('Enter your email address') ?>"
                                data-validate="{required:true, 'validate-email':true}"/>
                </div>
            </div>
            <div class="actions">
                <button class="action subscribe primary" title="<?php /* @escapeNotVerified */ echo __('Subscribe') ?>" type="submit">
                    <span><?php /* @escapeNotVerified */ echo __('Subscribe') ?></span>
                </button>
            </div>
        </form>
    </div>
</div>

Subscribe.php

<?php

namespace Magento\Newsletter\Block;

class Subscribe extends \Magento\Framework\View\Element\Template
{
    /**
     * Retrieve form action url and set "secure" param to avoid confirm
     * message when we submit form from secure page to unsecure
     *
     * @return string
     */
    public function getFormActionUrl()
    {
        $checkSubscriber = $this->_subscriber->loadByEmail($email); 
                    if ($checkSubscriber->isSubscribed()) {
                        $response = [
                            'status' => 'ERROR',
                            'msg' => __('Something went wrong with the subscription.'),
                        ];                        

                    }
        return $this->getUrl('newsletter/subscriber/new', ['_secure' => true]);
    }
}
?>

Please help this task ???

  • Exactly what problem you are facing. Newsletter subscribed or email not sending ?? – Narendra Vyas Mar 19 at 14:14
  • If you are on your local then emails wont send if you are not using any extension to send emails using SMTP. – Narendra Vyas Mar 19 at 14:16
  • i will added the SMTP extension but subscribe its not working – SUDHAKAR ARUNACHALAM Mar 19 at 14:19
  • what error are you getting on newsletter subscribe ? Check its status in my account as well – Narendra Vyas Mar 19 at 14:20
  • In default 2.2.5 it is working. Which Magento version do you have ? Also what is the error on subscribing – Narendra Vyas Mar 19 at 14:21
0

it is simply your logic issue,

$checkSubscriber = $this->_subscriber->loadByEmail($email);

Where you getting $email.

Also,

$checkSubscriber = $this->_subscriber->loadByEmail($email); 
                    if ($checkSubscriber->isSubscribed()) {
                        $response = [
                            'status' => 'ERROR',
                            'msg' => __('Something went wrong with the subscription.'),
                        ];                        

                    }

Is not right. Because of form action is newsletter/subscriber/new and HOW will get the response from this URL to the current page?

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.