PHP code example of codebaby / email
1. Go to this page and download the library: Download codebaby/email library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
codebaby / email example snippets
namespace CodeBaby\Email\Controller\CbDemo;
use CodeBaby\Email\Model\Service\MailService;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\App\ActionInterface;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\JsonFactory;
class Index implements ActionInterface, HttpGetActionInterface, HttpPostActionInterface
{
private MailService $mailService;
private JsonFactory $jsonFactory;
public function __construct(MailService $mailService, JsonFactory $jsonFactory)
{
$this->mailService = $mailService;
$this->jsonFactory = $jsonFactory;
}
public function execute()
{
$sendTo = [ 'email' => '[email protected] ' ];
$sender = [
"email" => "[email protected] ",
"name" => "Sender Name"
];
$templateVars = [
"test1" => "Test",
"test2" => "Test 2"
];
$subject = "Custom Subject";
$areaCode = "frontend";
$storeId = '0';
$cc = [
"[email protected] ",
"[email protected] "
];
$bcc = [
"[email protected] ",
"[email protected] "
];
$replyTo = '[email protected] ';
$template = null;
$result = $this->mailService->handle(
$sendTo,
$sender,
$templateVars,
$subject,
$areaCode,
$storeId,
$cc,
$bcc,
$replyTo,
$template
);
$json = $this->jsonFactory->create();
$json->setData($result);
return $json;
}
}