我正在使用 Mailgun 作为我的电子邮件服务提供商向我的同事发送电子邮件。我创建了一些有吸引力的电子邮件模板。但是,我不知道如何通过Mailgun发送它。请指导我......
答案 0 :(得分:1)
如果您使用mailgun中的PHP库,这很容易做到,可在此处找到:https://github.com/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>'
));
答案 1 :(得分:1)
或者您可以对模板进行文件读取并暂时存储:
$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));
答案 2 :(得分:0)
试试这个
$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]);