首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MailGun附件未显示

MailGun附件未显示
EN

Stack Overflow用户
提问于 2020-05-08 21:06:29
回答 2查看 111关注 0票数 0

显示的电子邮件中没有附加任何文件。我在test/test.txt上有一个不能附加的文本文件。下面是一个简单的函数。使用时,电子邮件显示时不带附件:

代码语言:javascript
复制
function send_email_with_attachment($email,$name){
    $mgClient = new Mailgun(MAILGUN_KEY);
    $domain = "mg.example.com";

    $file = array(
        array(
            'filePath' => 'test',
            'filename' => 'test.txt'
        )
    );

    $result = $mgClient->sendMessage($domain,array(
        "from"    => "Company Support <support@example.com>",
        "to"      => "{$name}<{$email}>",
        "subject" => "File Attached",
        "text"    => "Here is a cool text file",
        'attachment' => json_encode($file)
    )); 
}
EN

回答 2

Stack Overflow用户

发布于 2020-05-08 21:22:52

为什么不像这样直接使用附件:

代码语言:javascript
复制
$result = $mgClient->sendMessage($domain,array(
        "from"    => "Company Support <support@example.com>",
        "to"      => "{$name}<{$email}>",
        "subject" => "File Attached",
        "text"    => "Here is a cool text file",
        'attachment' => [
    ['filePath'=>'/test.txt', 'filename'=>'test']
  ]
    )); 

试着从官方代码中获取以下代码:

代码语言:javascript
复制
$mg->messages()->send('example.com', [
  'from'    => 'bob@example.com', 
  'to'      => 'sally@example.com', 
  'subject' => 'Test file path attachments', 
  'text'    => 'Test',
  'attachment' => [
    ['filePath'=>'/tmp/foo.jpg', 'filename'=>'test.jpg']
  ]
]);
票数 0
EN

Stack Overflow用户

发布于 2020-05-08 22:17:34

这个问题与我对Mailgun如何显示示例filePathfilename变量值的困惑有关。

如上所述,这里有一个来自MailGun的例子:

代码语言:javascript
复制
$mg->messages()->send('example.com', [
  'from'    => 'bob@example.com', 
  'to'      => 'sally@example.com', 
  'subject' => 'Test file path attachments', 
  'text'    => 'Test',
  'attachment' => [
    ['filePath'=>'/tmp/foo.jpg', 'filename'=>'test.jpg'] //what? Which file is being sent?
  ]
]);

这里有几个值得我注意的地方:

  1. 首先是我使用的是相对于php文件的路径,而不是我的服务器的根目录。
  2. 第二是我不理解邮件枪的例子。在本例中,发送的是哪个文件?对我来说,这个例子可能会更清楚:

代码语言:javascript
复制
$mg->messages()->send('example.com', [
  'from'    => 'bob@example.com', 
  'to'      => 'sally@example.com', 
  'subject' => 'Test file path attachments', 
  'text'    => 'Test',
  'attachment' => [
    ['filePath'=>'/tmp/foo.jpg', 'filename'=>'foo.jpg'] //this is a better way to demonstrate
  ]
]);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61679887

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档