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?
-
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 ?– ClaimsCommented 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 benCommented Nov 10, 2021 at 14:15
Add a comment
|
1 Answer
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);