MailGun附件未显示PHP

问题描述 投票:0回答:1

显示电子邮件,没有附件。我在test / test.txt上有一个文本文件,该文件不会附加。这是一个简单的功能。使用时,电子邮件将显示为不带附件:

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 <[email protected]>",
        "to"      => "{$name}<{$email}>",
        "subject" => "File Attached",
        "text"    => "Here is a cool text file",
        'attachment' => json_encode($file)
    )); 
}
php mailgun
1个回答
0
投票

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

$result = $mgClient->sendMessage($domain,array(
        "from"    => "Company Support <[email protected]>",
        "to"      => "{$name}<{$email}>",
        "subject" => "File Attached",
        "text"    => "Here is a cool text file",
        'attachment' => [
    ['filePath'=>'/test.txt', 'filename'=>'test']
  ]
    )); 
© www.soinside.com 2019 - 2024. All rights reserved.