0

I need to create a new button in edit address book page, and an email will be sent once we click on this button, any suggestions please?

2
  • You can trigger an ajax request when the button is clicked and deal with the email in the controller...or even do that in the address save controller. What have you tried ? Where are you stuck ?
    – Claims
    Commented Nov 10, 2021 at 14:05
  • acn you be more clear because it's new for me, if you have a tutorial, Thank you
    – sara ben
    Commented Nov 10, 2021 at 14:15

1 Answer 1

0

On your submit button add a js function :

<button type="button" onclick="sendMail()"><?= __('Continue') ?></button>


<script>
    var sendMail = function() {
        /*retrieve all the data you want
        var formData = ...
        */
                jQuery.ajax({
                    type: 'POST',
                    url: '<?= $block->getUrl('*/*/mail') ?>',
                    data: formData,
                    success: function (data) {
                        form.submit();
                    }
                });
        }
</script>

Then in your Mail controller; you can simply send the mail getting all the data you want from the data sent by the request as params.

 //Send mail
 $from = "xxx";
 $dest = "yyy";
 $title = "zzz";
 $mailContent = "azerty";
 $headers = 'From: '.$from. "\n" .
            'To: '.$dest . "\n" .
             'Content-type: text/html; charset=utf-8'."\n".
             'X-Mailer: PHP/' . phpversion();
 mail($dest, $title, $linesContent, $headers);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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