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

Php 如何通过邮枪发送电子邮件模板?,php,email,sendmail,mailgun,Php,Email,Sendmail,Mailgun,我使用Mailgun作为电子邮件服务提供商向同事发送电子邮件。我创建了一些有吸引力的电子邮件模板。但是,我不知道如何通过邮枪发送。请引导我 如果您使用的是mailgun的PHP库,这很简单,可在以下位置获得: 下面的代码将向您的同事发送电子邮件,您可以根据需要向字段添加任意数量的内容! 然后只需编辑数组“html”:)并执行脚本 # Include the Autoloader (see "Libraries" for install instructions) require 'vendor/

我使用Mailgun作为电子邮件服务提供商向同事发送电子邮件。我创建了一些有吸引力的电子邮件模板。但是,我不知道如何通过邮枪发送。请引导我

如果您使用的是mailgun的PHP库,这很简单,可在以下位置获得:

下面的代码将向您的同事发送电子邮件,您可以根据需要向字段添加任意数量的内容! 然后只需编辑数组“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>'
));
#包括自动加载器(有关安装说明,请参阅“库”)
需要“vendor/autoload.php”;
使用邮枪\邮枪;
#实例化客户端。
$mgClient=新邮枪('key-3AX6NJP29JD6FDS4GC373SGVJXTEOL0L');
$domain=“YOURDomain.mailgun.org”;
#给客户打电话。
$result=$mgClient->sendMessage($domain,array)(
'来自'=>'You@yourdomain.com',
'到'=>'您的_colleague@someone.com',
“主题”=>“你好”,
“html”=>“一些html代码在这里运行正常”
));

或者您可以读取模板的文件并将其临时存储:

$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));
$fileloc=fopen(“/path/to/email_template.php”,“r”);
$fileread=fread($fileloc,filesize(“/path/to/email_template.php”);
#实例化客户端。
$mg=新邮枪(“”);
$domain=“domain.com”;
#给客户打电话。
$mg->sendMessage($domain,array('from'=>'noreply@domain.com', 
'到'=>'recipient@domain.com', 
“主题”=>“主题”,
'html'=>$fileread));
试试这个

$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]);

@api Sherriff orlie如何在这些html电子邮件中添加自定义参数。我想在html模板中添加一个字段,然后再从php设置它的值。你能帮我做到这一点吗。