mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-12-01 17:36:05 +03:00
Add template support when using BatchMessage (#786)
* Add support for Mailgun templates when using BatchMessages * Fixed quatation marks in error message * Comment change * Change function comment style
This commit is contained in:
parent
4db9d9bb63
commit
f25a22344b
@ -114,8 +114,8 @@ class BatchMessage extends MessageBuilder
|
||||
throw MissingRequiredParameter::create('subject');
|
||||
}
|
||||
|
||||
if (empty($message['text']) && empty($message['html'])) {
|
||||
throw MissingRequiredParameter::create('text" or "html');
|
||||
if (empty($message['text']) && empty($message['html']) && empty($message['template'])) {
|
||||
throw MissingRequiredParameter::create('text", "html" or "template');
|
||||
}
|
||||
|
||||
$message['recipient-variables'] = json_encode($this->batchRecipientAttributes);
|
||||
|
@ -231,6 +231,16 @@ class MessageBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $template Name of the Mailgun template
|
||||
*/
|
||||
public function setTemplate(string $template): self
|
||||
{
|
||||
$this->message['template'] = $template;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addCustomHeader(string $headerName, $headerData): self
|
||||
{
|
||||
if (!preg_match('/^h:/i', $headerName)) {
|
||||
|
@ -30,8 +30,10 @@ $builder->addToRecipient("john.doe@example.com", array("first" => "John", "last"
|
||||
$builder->addCcRecipient("sally.doe@example.com", array("full_name" => "Sally Doe"));
|
||||
# Define the subject.
|
||||
$builder->setSubject("A message from the PHP SDK using Message Builder!");
|
||||
# Define the body of the message.
|
||||
# Define the body of the message (One is required).
|
||||
$builder->setTextBody("This is the text body of the message!");
|
||||
$builder->setHtmlBody("<html><p>This is the HTML body of the message</p></html>");
|
||||
$builder->setTemplate("template_name");
|
||||
|
||||
# Other Optional Parameters.
|
||||
$builder->addCampaignId("My-Awesome-Campaign");
|
||||
@ -61,8 +63,10 @@ $batchMessage = $mg->messages()->getBatchMessage("example.com");
|
||||
$batchMessage->setFromAddress("me@example.com", array("first"=>"PHP", "last" => "SDK"));
|
||||
# Define the subject.
|
||||
$batchMessage->setSubject("A Batch Message from the PHP SDK!");
|
||||
# Define the body of the message.
|
||||
$batchMessage->setTextBody("This is the text body of the message!");
|
||||
# Define the body of the message (One is required).
|
||||
$builder->setTextBody("This is the text body of the message!");
|
||||
$builder->setHtmlBody("<html><p>This is the HTML body of the message</p></html>");
|
||||
$builder->setTemplate("template_name");
|
||||
|
||||
# Next, let's add a few recipients to the batch job.
|
||||
$batchMessage->addToRecipient("john.doe@example.com", array("first" => "John", "last" => "Doe"));
|
||||
|
Loading…
Reference in New Issue
Block a user