Google App Engine GAE Php发送附件

时间:2014-02-24 19:57:59

标签: php google-app-engine email yaml email-attachments

您好我正在尝试在Google应用引擎中为我的应用添加一些附件。我发送电子邮件并获取正文和主题,但由于某种原因,附件没有通过谷歌方法解释它并没有真正做到任何正义。

这是我的app.yaml文件

application: 'phpmail' 
version: 1
runtime:php
api_version:1
threadsafe: true

handlers:
-url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico

-url: .*
script:main.php

这是main.php文件

<html>
<head> 
other info I have
</head>
<body>
<?php
require_once 'google/appengine/api/mail/Message.php';

use google\appengine\api\mail\Message;

// ...

$message_body = "...";

$mail_options = [
"sender" => "sender@gmail.com",
"to" => "reciever@yahoo.com",
"cc" => "reciever@aol.com",
"subject" => "Your account has been activatedd",
"textBody" => "Guten tag, here is an email, with hopefully two attachments",
];
image= open('./file1.png', 'file2.jpg')
        message.attachments=[(file1.png, file2.jpg())]
        image.close()
try {
  $message = new Message($mail_options);
  $message->send();
} catch (InvalidArgumentException $e) {
echo $e;
  }
{
   echo "Your message has been sent";
  }
?>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

我看不到你添加的代码是如何执行的。无论如何,这是一种方法。

$subject = uniqid();
$content = "Hello, world!";

$message = new Message();
$from = createMailAddress();
$message->setSender($from);
$to = createMailAddress();
$message->addTo($to);
$message->setTextBody($content);
$message->setSubject($subject);
$message->addAttachment('data.txt', 'Here is some text as an attachment');
$message->send();