I have a site developed with Drupal 8. I created a REST API to consume from the app and also from another site and they work well.

What I have not been able to do is send an email through an API I am trying to create. I can send mail from the site with webform, the SMTP is configured correctly, but (for example) when I use "simple_mail_send", it does not send the mail and yet "result" is true.
I also tried with MailManager and the same thing happens.

Part of the code that I am using

   $to = 'to_mail@gmail.com';
   $from = 'from_mail@email.xx';
   $subject = 'prueba de correo';
   $message ='Prueba de correo usando simple_mail_send';
   $result = simple_mail_send($from, $to, $subject, $message);
   $resultado = $result;
   return new JsonResponse($resultado);

This is json response:

    "id": "simple_mail_simple_mail",
    "module": "simple_mail",
    "key": "simple_mail",
    "to": "to_mail@gmail.com",
    "from": "from_mail@email.xx",
    "reply-to": "from_mail@email.xx",
    "langcode": {},
    "params": {
        "subject": "prueba de correo",
        "body": "Prueba de correo usando simple_mail_send"
    "send": true,
    "subject": "prueba de correo",
    "body": "Prueba de correo usando simple_mail_send",
    "headers": {
        "MIME-Version": "1.0",
        "Content-Type": "text/html; charset=UTF-8;",
        "Content-Transfer-Encoding": "8Bit",
        "X-Mailer": "Drupal",
        "Return-Path": "from_mail@email.xx",
        "Sender": "from_mail@email.xx",
        "From": "Catastro Nacional <from_mail@email.xx>",
        "Reply-to": "from_mail@email.xx"
    "result": true

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.