简体   繁体   English

如何通过Mailgun发送电子邮件模板?

[英]How to send E-mail Templates through Mailgun?

I am using Mailgun as my e-mail Service provider for sending E-mail to my Colleagues. 我使用Mailgun作为我的电子邮件服务提供商向我的同事发送电子邮件。 I have created some attractive E-mail Templates. 我创建了一些有吸引力的电子邮件模板。 But, I don't know how to send it through Mailgun. 但是,我不知道如何通过Mailgun发送它。 Kindly guide me... 请指导我......

this is simple to do if you're using the PHP library from mailgun, available here: https://github.com/mailgun/mailgun-php 如果您使用的是来自mailgun的PHP库,这很简单: https//github.com/mailgun/mailgun-php

The below code will send an email to a colleague of yours, you can add as many to fields as you need! 以下代码将向您的同事发送电子邮件,您可以根据需要添加任意数量的字段! Then simply edit the array 'html' :) and execute the script! 然后只需编辑数组'html':)并执行脚本!

# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0l');
$domain = "YOURDomain.mailgun.org";

# Make the call to the client.
$result = $mgClient->sendMessage($domain, array(
    'from'    => 'You@yourdomain.com',
    'to'      => 'your_colleague@someone.com',
    'subject' => 'Hello',
    'html'    => 'some html code <b> goes here </b> and works <span style=\"color:red\">fine</span>'
));

Or you can do a file read of the template and store it temporarily: 或者,您可以对模板执行文件读取并临时存储:

$fileloc = fopen("/path/to/email_template.php", 'r');
$fileread = fread($fileloc, filesize("/path/to/email_template.php"));

# Instantiate the client.
$mg = new Mailgun('<your_api_key>');
$domain = "domain.com";

# Make the call to the client.
$mg->sendMessage($domain, array('from'    => 'noreply@domain.com', 
                            'to'      => 'recipient@domain.com', 
                            'subject' => 'Subject', 
                            'html'    => $fileread));

Try this 尝试这个

$content = view('email.info-request',
            ['sender_name' => Input::get('sender_name'),
             'sender_email' => Input::get('senderr_email'),
             'sender_subject' => Input::get('sender_subject'),
             'sender_message' => Input::get('sender_message')])->render();

$mg->messages()->send('mydomain.com', [
            'from'    => Input::get('sender_email'),
            'to'      => 'admin@mydomain.com',
            'subject' => 'Information Request',
            'html'    => $content]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM