Hi,
I've a little problem with token module.
I defined an action, when someone writes a post, the system must to send an email to an email account. I choosen tokenized e-mail,
because in this way it is possible to see the node the new post belongs to.
I already made the changes on the file modules/token/token_actions.module
token_replace_all with token_replace_multiple

Now the problem:
If someone writes a post, the system returns an error:
Unable to send e-mail. Please contact the site admin, if the problem persists.
and the admin receives this email:

subject: Mail failure - malformed recipient address

----------start email

A message that you sent contained one or more recipient addresses that were
incorrectly constructed:

New post on my New Drupal site: missing or malformed local part (expected word or "<")

This address has been ignored. There were no other addresses in your
message, and so no attempt at delivery was possible.

------ This is a copy of your message, including all the headers. ------

To: Nuovo post sul sito R&D CSP
Subject:
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes
Content-Transfer-Encoding: 8Bit
X-Mailer: Drupal
Errors-To: mail@domain.it
Return-Path: mail@domain.it
Sender: mail@domain.it
Reply-To: mail@domain.it
From: mail@domain.it
Message-Id:
Date: Wed, 30 Apr 2008 12:25:06 +0200
----------end email

With some debugs I notice that on the function drupal_mail the value recipients is mapped as Subject.
How I can sove this problem?
I'm using drupal 6.1, and I notice the same error on drupal 6.2
Best Regards
Tonio

Comments

seanr’s picture

Status: Active » Needs work
StatusFileSize
new1.75 KB

Drupal's mail function changed significantly in Drupal 6. See attached patch. Haven't tested it myself yet at all, so I marked it as code needs work.

superjacent’s picture

Subscribe - (sorry for duplication - I posted a similar problem here http://drupal.org/node/242944#comment-836294)

greggles’s picture

Title: Send tokenized e-mail » "Unable to send mail" with send tokenized e-mail

Slightly improved title.

@superjacent and @redfox75 - can you test seanr's patch in #1?

superjacent’s picture

It's not working for me. Get this error:
Parse error: syntax error, unexpected T_VARIABLE in /home/.../public_html/.../drupal-6.2/sites/all/modules/token/token_actions.module on line 140.

Line 140 is in this piece of code:

function token_actions_mail($key, &$message, $params) {
$message['subject'] = $params['subject']
$message['body'] = $params['body'];
}
greggles’s picture

StatusFileSize
new1.83 KB

@superjacent - that's a parser error because it expected a semicolon.

re-rolled patch fixes that and applies cleanly.

calebtr’s picture

greggles, I applied your patch and noticed that e-mail message bodies were still empty

+  $params['message'] = drupal_html_to_text(token_replace_multiple($context['message'], $context));

should be

+  $params['body'] = drupal_html_to_text(token_replace_multiple($context['message'], $context));

But I'm also noticing that I still get the 'unable to send email' error when my action is assigned to saving a comment rather than creating a node. Sending e-mail works on the node action, but not the comment action. I'm not seeing anything in the code in token - maybe something in actions.inc?

greggles’s picture

Status: Needs work » Needs review
StatusFileSize
new1.98 KB

@calebtr - thanks for finding that. I've re-rolled it to include that change.

Did you try this for users or taxonomies?

Since this seems to fix at least some of the cases I feel like it's probably worth committing and have moved it back to CNR to reflect that. Additional reviews would be awesome.

greggles’s picture

Status: Needs review » Fixed

Thanks for the patch and reviews, seanr and calebtr! I've now committed this to 6.x - http://drupal.org/cvs?commit=127492

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

dave reid’s picture

Status: Closed (fixed) » Active

There also is one more thing... in token_actions.module, line 151 needs to be modified. I ran into a problem with Mollom trying to alter a new comment mail sent out by token module. It was expecting $message['body'] to be an array. I took a look at some other examples in core (e.g. contact_mail in contact.module) and confirmed that this is the correct behavior.

Currently:

function token_actions_mail($key, &$message, $params) {
  $message['subject'] = $params['subject'];
  $message['body'] = $params['body'];
}

Should Be:

  $message['body'][] = $params['body'];
greggles’s picture

Status: Active » Needs review
StatusFileSize
new703 bytes

Great. This makes it work for me on a test site.

greggles’s picture

Status: Needs review » Fixed

And I've now committed that fix - http://drupal.org/cvs?commit=131207

Thanks, Dave Reid!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.