I have very simple form with summernote (wysiwyg-editor). I use this some kind of message center where user can send emails.
My controller:
$emailtopic = request('emailtopic');
$detail = request('summernoteInput');
$dom = new \domdocument();
//$dom->loadHtml($detail, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$dom->loadHtml(mb_convert_encoding($detail, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$images = $dom->getelementsbytagname('img');
foreach($images as $k => $img){
$data = $img->getattribute('src');
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
$image_name= time().$k.'.png';
$path = public_path() .'/'. $image_name;
file_put_contents($path, $data);
$img->removeattribute('src');
$img->setattribute('src', $image_name);
//$attachimages[] = $image_name;
}
$detail = $dom->savehtml();
/* Luodaan sähköpostin pohjatiedot */
$objEmailinfo = new \stdClass();
$objEmailinfo->replyto = 'henri.karhunen@gmail.com';
$objEmailinfo->topic = $emailtopic;
$objEmailinfo->attachimages = $path;
/* Lähetetään sähköpostit käyttäjälle */
$objEmailcontent = new \stdClass();
$objEmailcontent->content = $detail;
Mail::to('henri.karhunen@gmail.com')->send(new DefaultMessagecenter($objEmailinfo, $objEmailcontent));
swal()->message('Viesti','Viestin lähetys onnistui!','success',['timer'=>2000]);
return view('messagecenter', [
'PageTopic' => __('leftmenu.Message center'),
'teamlist' => $teamlist,
]);
My email:
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class DefaultMessagecenter extends Mailable
{
use Queueable, SerializesModels;
public $emailinfo;
public $emailcontent;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($emailinfo, $emailcontent)
{
$this->emailinfo = $emailinfo;
$this->emailcontent = $emailcontent;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->replyTo($this->emailinfo->replyto)
->view('emails.defaultemail')
->subject($this->emailinfo->topic)
->with(
[
]
);
}
}
defaultemail.blade.php:
{!! $emailcontent->content !!}
That embed works but how I can convert all pictures inside $emailcontent->content embedded pictures? Then pictures going right place on email. If I loop all picturename that $message->embed I got all pictures end of email body. I wanna put all images on correct place. So basicly I must somehow replace all normal
It is possibly?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire