Last active
July 19, 2018 09:05
-
-
Save dbatten5/66b298ca02b0be1093ca8ca801713cb9 to your computer and use it in GitHub Desktop.
Issue with adding a asm_group_id into an email template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> | |
<a href="<%asm_group_unsubscribe_raw_url%>">Unsubscribe</a> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Mail; | |
use App\Email; | |
use Illuminate\Mail\Mailable; | |
class EmailTemplate extends Mailable implements ShouldQueue | |
{ | |
use Queueable, SerializesModels; | |
protected $email; | |
protected $emailData; | |
public function __construct(Email $email, $emailData) | |
{ | |
$this->email = $email; | |
$this->emailData = $emailData; | |
} | |
public function build() | |
{ | |
$emailData = $this->emailData; | |
$args = [ | |
'asm_group_id' => 6441, | |
'to' => [ | |
$this->email->address, | |
], | |
'sub' => [ | |
'%Unsubscribe%' => ['<%asm_group_unsubscribe_url%>'], | |
'%rawUnsubscribe%' => ['<%asm_group_unsubscribe_raw_url%>'], | |
], | |
]; | |
$header = $this->asString($args); | |
$this->withSwiftMessage(function ($message) use ($header) { | |
$message->getHeaders()->addTextHeader('X-SMTPAPI', $header); | |
}); | |
$email = $this | |
->to($this->email->address) | |
->from('[email protected]') | |
->subject('testing') | |
->view('mail.template') | |
->with([ | |
'content' => $emailData['content'], | |
]); | |
return $email; | |
} | |
private function asJSON($data) | |
{ | |
$json = json_encode($data); | |
$json = preg_replace('/(["\]}])([,:])(["\[{])/', '$1$2 $3', $json); | |
return $json; | |
} | |
private function asString($data) | |
{ | |
$json = $this->asJSON($data); | |
return wordwrap($json, 76, "\n "); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('mail.email-index') | |
@section('content') | |
<td align="center"> | |
<table class="container566" align="center" border="0" width="566" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt"> | |
<tr> | |
<td> | |
<table class="container566" align="center" border="0" width="566" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt"> | |
<tr> | |
<td align="left" style="font-family:Lucida Sans Unicode, sans-serif, Arial, Tahoma; Font-size:14px; line-height:18px; font-weight:bold; font-style:normal; color:#374651; padding-top:26px;"> | |
</td> | |
</tr> | |
<tr> | |
<td align="left" style="font-family:Lucida Sans Unicode, sans-serif, Arial, Tahoma; Font-size:14px; line-height:18px; font-weight:normal; font-style:normal; color:#374651; padding-top:16px;"> | |
@markdown($content) | |
</td> | |
</tr> | |
</table> | |
</td> | |
</tr> | |
</table> | |
@endsection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment