0
votes

All I need from my server is to be able to send emails to my users when they forget their password. I try the code below after installing the Google App Engine SDK for PHP and it gives me the error

Fatal error: require_once(): Failed opening required 'google/appengine/api/mail/Message.php' (include_path='.:') in /Library/WebServer/Documents/AppEngine/testMail.php on line 2

This is my code:

require_once 'google/appengine/api/mail/Message.php';

use google\appengine\api\mail\Message;

try {
    $message = new Message();
    $message->setSender('[email protected]');
    $message->addTo('[email protected]');
    $message->setSubject('Example email');
    $message->setTextBody('Hello, world!');
    $message->send();
    echo 'Mail Sent';
} catch (InvalidArgumentException $e) {
    echo 'There was an error';
}

I'm thinking that I did not install the engine properly but I'm lost at this point. Any ideas?

1

1 Answers

0
votes

Well, two things. First of all, you don't need the require_once statement. At least I've never had to use that (maybe you did need it in older versions of GAE but as far as I know, it isn't needed. Your php script is currently trying to open a directory that doesn't exist in your project.) All you need is the use google\appengine\api\mail\Message; statement.

Secondly, when you setSender, you need to make sure that your email '[email protected]' is a registered email in your google app engine app -> otherwise no actual email will get sent.

Hope that helps.