Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En esta guía, se describe cómo usar la API de correo para enviar y recibir correos electrónicos.
Antes de comenzar
Debes registrar los correos electrónicos de tus remitentes como remitentes autorizados. Para obtener más información, consulta quién puede enviar correos electrónicos.
Envía correos electrónicos
La función mail() integrada de PHP puede enviar correos electrónicos a través de la API de correo electrónico de App Engine. Esto debería funcionar bien con la mayoría de los códigos existentes, siempre que se adapte a las restricciones que se enumeran en la sección Envía correos electrónicos.
Otra alternativa es hacer llamadas directas a la API de correo electrónico de la siguiente manera:
use google\appengine\api\mail\Message;// Notice that $image_content_id is the optional Content-ID header value of the// attachment. Must be enclosed by angle brackets (<>)$image_content_id = '<image-content-id>';// Pull in the raw file data of the image file to attach it to the message.$image_data = file_get_contents('image.jpg');try { $message = new Message(); $message->setSender('from@example.com'); $message->addTo('to@example.com'); $message->setSubject('Example email'); $message->setTextBody('Hello, world!'); $message->addAttachment('image.jpg', $image_data, $image_content_id); $message->send(); echo 'Mail Sent';} catch (InvalidArgumentException $e) { echo 'There was an error';}
Cómo recibir correos electrónicos
Puedes configurar la aplicación para que reciba correos electrónicos entrantes en las direcciones con el siguiente formato:
anything@appid.appspotmail.com
Para recibir correos electrónicos, realiza los siguientes pasos:
Habilita el correo electrónico entrante en el archivo app.yaml de tu app: Agrega lo siguiente a la sección inbound_services:
-mail
En tu archivo de configuración, crea mapeos a partir de rutas de URL que representen direcciones de correo electrónico a los controladores en el código de tu app. El patrón /_ah/mail/.+ hace que todas las direcciones de correo electrónico entrantes coincidan de la siguiente manera:
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[[["\u003cp\u003eThis guide outlines how to utilize the Mail API for sending and receiving emails within the context of App Engine, particularly for first-generation runtimes.\u003c/p\u003e\n"],["\u003cp\u003ePHP's built-in \u003ccode\u003email()\u003c/code\u003e function can send emails using the App Engine Mail API, and direct calls to the API are also possible using the \u003ccode\u003egoogle\\appengine\\api\\mail\\Message\u003c/code\u003e class.\u003c/p\u003e\n"],["\u003cp\u003eBefore sending emails, you must register your sender email addresses as authorized senders, according to the Mail API's guidelines.\u003c/p\u003e\n"],["\u003cp\u003eTo receive emails, enable incoming mail in your \u003ccode\u003eapp.yaml\u003c/code\u003e file, create URL mappings for incoming email addresses, and implement handlers in your app's code to process the received mail using the Mailparse extension.\u003c/p\u003e\n"],["\u003cp\u003eYour app can receive incoming emails at addresses formatted as \u003ccode\u003eanything@appid.appspotmail.com\u003c/code\u003e, even if your app is deployed on a custom domain, as you cannot use custom domain addresses to receive emails.\u003c/p\u003e\n"]]],[],null,["# Sending and Receiving Mail with the Mail API\n\nThis guide describes how to use the Mail API to send and receive mail.\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| php-gen2\n|\n| /services/access). If you are updating to the App Engine PHP 7/8 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/php-differences) to learn about your migration options for legacy bundled services.\n\nBefore you begin\n----------------\n\nYou must register your sender emails as authorized senders. For more\ninformation, see\n[who can send email](/appengine/docs/legacy/standard/python/mail#who_can_send_mail).\n\nSending mail\n------------\n\nPHP's built-in [`mail()`](https://php.net/manual/en/function.mail.php)\nfunction can send emails via App Engine Mail API. This should work well with\nmost existing code as long as it conforms to the restrictions listed in the\n[Sending mail](#Sending_mail).\n\nAlternatively, you can make direct calls to the Mail API: \n\n use google\\appengine\\api\\mail\\Message;\n\n // Notice that $image_content_id is the optional Content-ID header value of the\n // attachment. Must be enclosed by angle brackets (\u003c\u003e)\n $image_content_id = '\u003cimage-content-id\u003e';\n\n // Pull in the raw file data of the image file to attach it to the message.\n $image_data = file_get_contents('image.jpg');\n\n try {\n $message = new Message();\n $message-\u003esetSender('from@example.com');\n $message-\u003eaddTo('to@example.com');\n $message-\u003esetSubject('Example email');\n $message-\u003esetTextBody('Hello, world!');\n $message-\u003eaddAttachment('image.jpg', $image_data, $image_content_id);\n $message-\u003esend();\n echo 'Mail Sent';\n } catch (InvalidArgumentException $e) {\n echo 'There was an error';\n }\n\nReceiving mail\n--------------\n\nYou can set up your app to receive incoming email at addresses in the following\nformat: \n\n anything@appid.appspotmail.com\n\n| **Note:** Even if your app is deployed on a custom domain, you can't receive email sent to addresses in that domain.\n\nTo receive email:\n\n1. Enable incoming mail in your app's `app.yaml` file. Add the following to the\n `inbound_services`:\n\n - mail\n\n2. In your configuration file, create mappings from URL paths that represent\n email addresses to handlers in your app's code. The pattern `/_ah/mail/.+`\n matches all incoming email addresses:\n\n - url: /_ah/mail/.+\n script: handle_incoming_email.php\n login: admin\n\n3. Implement code for the handlers you specified in your application code.\n\n You can read the MIME data from\n [php://input](https://php.net/manual/en/wrappers.php.php#wrappers.php.input) and parse the email\n content using [Mailparse](http://php.net/manual/en/book.mailparse.php)."]]