显示的电子邮件中没有附加任何文件。我在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 <support@example.com>",
"to" => "{$name}<{$email}>",
"subject" => "File Attached",
"text" => "Here is a cool text file",
'attachment' => json_encode($file)
));
}发布于 2020-05-08 21:22:52
为什么不像这样直接使用附件:
$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']
]
)); 试着从官方代码中获取以下代码:
$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']
]
]);发布于 2020-05-08 22:17:34
这个问题与我对Mailgun如何显示示例filePath和filename变量值的困惑有关。
如上所述,这里有一个来自MailGun的例子:
$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?
]
]);这里有几个值得我注意的地方:
$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
]
]);https://stackoverflow.com/questions/61679887
复制相似问题