dongxing4643 2014-02-24 19:57
浏览 49

Google App Engine GAE Php发送附件

Hello I'm trying to add a few attachments to my app in Google app engine. I send the email and get the body as well as the subject but for some reason the attachments don't come through and googles method of explaining it doesn't really do it any justice.

here is my app.yaml file

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

and here is the main.php file

<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条回答 默认 最新

  • dongliming2416 2014-02-24 23:57
    关注

    I don't see how the code you added even executes. Anyway, here's a way to do it.

    $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();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大