Module WAMP / Drupal 7 / SMTP: Can not send mail with drupal_mail, but & ldquo; test the mail & quot; can send

advertisements

I set up, with a Gmail account (smtp.gmail.com:465).

I'm using the SMTP module, and after setup, I can (i.e. have no problem with Gmail) send the "test e-mail" it offers in the admin page.

However, trying to call this function:

drupal_mail('casabaca_s3s', FORM_ALIAS_CONTACTO, '[email protected]', language_default(), array());

which is implemented here (hook impl.):

function casabaca_s3s_mail($key, &$message, $params)
{
    $data = array();
    foreach($params as $k => $v)
    {
        $data['${'.$k.'}'] = $v;
    }

    $messages = array(
        FORM_ALIAS_CONTACTO => array(
            'subject' => '',
            'html.message' => <<<MESSAGE
MESSAGE
        ),
        FORM_ALIAS_COTIZAR => array(
            'subject' => '',
            'html.message' => <<<MESSAGE
MESSAGE
        ),
        FORM_ALIAS_TALLERES => array(
            'subject' => '',
            'html.message' => <<<MESSAGE
MESSAGE
        ),
        FORM_ALIAS_EXONERADOS => array(
            'subject' => '',
            'html.message' => <<<MESSAGE
MESSAGE
        ),
        FORM_ALIAS_AVALUO => array(
            'subject' => '',
            'html.message' => <<<MESSAGE
MESSAGE
        ),
        FORM_ALIAS_MANTENIMIENTO => array(
            'subject' => '',
            'html.message' => <<<MESSAGE
MESSAGE
        ),
    );
    $base_message = $messages[$key];
    $message['body']['plain'] = '<html><body>HTML version of "test message"</body></html>'; //drupal_wrap_mail(drupal_html_to_text(strtr($base_message['html.message'], $data)));
    $message['body']['html'] = 'text version of "test messages"'; //drupal_wrap_mail(strtr($base_message['html.message'], $data));
    $message['subject'] = 'test subject';//$base_message['subject'];
    $headers = array(
        'MIME-Version' => '1.0',
        'Content-Type' => 'multipart/alternative; charset=UTF-8;',
        'Content-Transfer-Encoding' => '8Bit',
        'X-Mailer' => 'Drupal'
    );
    foreach ($headers as $key => $value) {
        $message['headers'][$key] = $value;
    }
}

doesn't work. The returned message comes as follows:

No se pudo enviar el correo electrónico. Contacte con la administración del sitio si persiste el problema.

(message in Spanish. possible English message could be - I don't know since I'm a total n00b and just using a Spanish Drupal 7 version -: E-mail couldn't be sent. Contact with site administration if the problem persists).

Q: What am I screwing? Hypothesis: I think it's in my code, but I copied most of it and try to understand it

Goal: send a multiple alternatives email (please note, currently the options are just a stub, and not implemented), depending on six possibilities (each responding to a different form, a different feature, but currently they have dummy body and subject).

Preconditions: Drupal 7, PHP 5.4.16, SMTP module 7.x-1.0.

Edit: For those not being sure what the "test e-mail" is, see Here for a detailed example.


Found it ... had many problems.

  1. The hook_mail implementation was in a file not yet included (required) in the .module, so it couldn't be found (and so, the message was empty, and that triggered the error).
  2. Using ['plain'] and ['html'] as message elements did not create the multipart/alternative. Had to create it explicitly (i.e. boundaries).
  3. There was something with the cache, because mail() was not bypassed (it was with the testing email but not with the actual email).

(summary: a 8th-layer error).