0
votes

I am using Google App Engine and am trying to send email alerts with the Mail PHP API. I have defined a class with a public function but whenever I run it I get this error:

PHP Fatal error: Class 'Message' not found in...

PHP Code:

use \google\appengine\api\mail\Message;

    class crawls {
        public function check() {
                   try {
                    $message = new Message();
                    $message->setSender('Name <[email protected]>');
                    $message->addTo($recipients);
                    $message->setSubject('Subject');
                    $message->setHTMLBody("<p>Message</p>");
                    $message->send();
                } catch (InvalidArgumentException $e) {
                    $error = "Unable to send mail. $e";
                }
    }
}

Everything works when I move the code outside of the class, but I want it inside the class.

2
try to include file and check the file if its in the folder - mohade
It's not a file to be included. - ajgisme
@user5331188 were you able to resolve this issue? If so it is recommended to post your solution as the answer here to better help the community. If not it is now recommended to use specific mail sending APIs outside of App Engine that are built for large mail distribution. - Jordan
@jordan yeah I couldn't fix this. Thanks for the info! - ajgisme

2 Answers

0
votes

Inherit Message class :

Define namespace if required.

class crawls extends \google\appengine\api\mail\Message {
    // your code
}
0
votes

Try this may it works for you:

class crawls {
    public function check() {
           try {
                $message = new \google\appengine\api\mail\Message();
                $message->setSender('Name <[email protected]>');
                $message->addTo($recipients);
                $message->setSubject('Subject');
                $message->setHTMLBody("<p>Message</p>");
                $message->send();
            } catch (InvalidArgumentException $e) {
                $error = "Unable to send mail. $e";
            }
    }
}

Hope it helps