【问题标题】:Google App Engine GAE Php send attachmentGoogle App Engine GAE Php 发送附件
【发布时间】:2014-03-26 16:51:23
【问题描述】:

您好,我正在尝试在 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>

【问题讨论】:

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


    【解决方案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();
    

    【讨论】:

    • 感谢您使我能够发送附件,但是我实际上无法在我的邮件提供商中查看它们,并且当我下载它们时,预览显示“文件“file.png”无法打开。它可能已损坏或使用了预览无法识别的文件格式。 - url: /images/(file.jpg) static_files /images/\1 upload: /images/file.jpg 我对上面的 app.yaml 文件做了一些更改也认为这可能会解决它,但无济于事。我觉得我很接近但无法到达那里。我还需要添加任何 mime 类型的代码吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-08
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    • 2017-09-24
    • 2011-03-11
    相关资源
    最近更新 更多