Effectively using Google App Engine to send lots of emails using PHP?

落花浮王杯 提交于 2019-12-21 06:41:04

问题


I currently have a client website on the Grid server on MediaTemple that will be moved to a Virtual Private Server soon. Currently it's using some hacks to trickle his massive email sendouts using cron jobs and queuing with the database (to avoid going over the limit MediaTemple set).

We can't use third party solutions (like MailChimp etc) as the price is just too much for the client to pay (he has 75,000+ people on his mailing list). So after lots of research, I've found that using Google App Engine as basically a scalable way to send out lots of emails is a viable option.

His site uses PHP at the moment. I do eventually want to use Python/Django, but not for the time being... There is a few things I don't quite understand... Such things as having the app called 'example.appspot.com', can this be a sub domain on his site (like mailapp.example.com)? After reading the user guide on Google App Engine it seems that the email address the app uses is an admin on the application (like admin@example.appspot.com)... that has to be that? It can't possibly be something like example@example.com?

I understand that sending out so many emails means I'll have to enable the billing on the application. I understand there is still a quota on how many I can send. I've even seen this code that could help set this up easily: http://github.com/tow/appengine-mailer

I ideally want to replace the PHP code where it sends out email (using mail() etc) and make it send out with Google App Engine instead.

Has anyone successfully done this sort of setup? Can anyone help me spell the steps required? Or provide any pitfalls to using such a system?


回答1:


Your first question:

having the app called 'example.appspot.com', can this be a sub domain on his site (like mailapp.example.com)?

Yes, as the FAQ say:

Google App Engine can be used with Google Apps to provide a custom domain name for your internet-facing application, e.g., myapp.com.

By default, when you deploy your service on Google App Engine, your service will be accessible at [your-application-id].appspot.com. In order to provide a stronger brand experience for your application, you may also want that application to be available at [my-brand].com or www.[my-brand].com.

In order to set up these branded access locations for your service, you must prove that you own the domain name or purchase the domain name through Google. Google App Engine allows you to prove ownership of your domain and purchase new domain names using Google Apps.

Your second question:

the email address the app uses is an admin on the application (like admin@example.appspot.com)... that has to be that? It can't possibly be something like example@example.com?

Sure, you can use the Google userids you want as your admin users for your apps.

I understand that sending out so many emails means I'll have to enable the billing on the application. I understand there is still a quota on how many I can send.

Yep, per the docs, $0.0001 per recipient emailed. With 75,000 people on the mailing list, that's $7.50 per mail sent to all of them. Per these other docs, the free quota is 2,000 recipients emailed per day, the absolute maximum is 7.4 millions (there also limits to the rate, i.e., how many recipients are mailed per minute in free and max quotas).

I ideally want to replace the PHP code where it sends out email (using mail() etc) and make it send out with Google App Engine instead.

Sorry, can't help you there, I run App Engine with Python, not PHP. But I hear that, with Quercus, it is possible to run PHP on the JVM "side" of App Engine.




回答2:


You can use appengine for PHP to send mails to users this way:

<?php

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

    $mail_options = [
        "sender" => 'you@example.com',
        "to" => $_POST['email'],
        "subject" => "Type a subject here",
        "textBody" => "Type message here",
            ];

    try {
    $message = new Message($mail_options);
    $message->send();
    } catch (InvalidArgumentException $e) {
    echo $e;
    }

?>


来源:https://stackoverflow.com/questions/3424625/effectively-using-google-app-engine-to-send-lots-of-emails-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!