Simplenews are not sent (Simplenews 6.x - 1.0-rc6, Drupal 6.12)
| Project: | Simplenews |
| Version: | 6.x-1.0-rc6 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Installed Simplenews 6.x - 1.0-rc6 on my Drupal 6.12.
Configured permissions to send letters and to subscribe to them.
Node type for newsletters is default "simplenews".
Have only one term for newsletters.
Created newsletter and submitted it as test newsletter on test address.
Got message that test newsletter is created and sent to test mail address
No letter is achived and newsletter is in the "draft issues".
Created some more newsletters - tried to sent it immidiately - allways says that issue is sent to mail address, newsletter is in database table simplenews_newsletter with s_status=2 But no letters are delivered to mail box.
It is not hosting issue because user registration (confirmation) letters are delivered without problems on that site from the same address supp@my_site.com.
It is not cron issue because I tryed to send newsletters immediately, not by cron.
It is not permission issue because permissions are configured properly and I tried to send newsletters from uid=1 account, so user access allways true.
What else can cause it? I'm lost.
What can I do else to make it work?

#1
Continue testing.
Created new newsletter with only one subscriber. Sent it immediately.
Got messages that "Newsletter sent" and "New content of type Newsletter was created".
The note about my newsletter appeared on the page /admin/content/simplenews/sent with status sent - "yes".
In the log of the site such messages:
"1 emails sent in 0 seconds."
"Outgoing email. Message type: node
Subject: [Newsletter of the site Test newsletter] Testing newsletter 10
Recipient: recipient@mail.ru"
But no newsletter is delivered to mailbox.
After that I send the letter to the same user through the contact form in his profile and in a second this letter got in mailbox of the user.
Both letters were sent from the same mail address supp@my-domain.com which is currently the admin mail address and site mail address and the address for sending newsletters.
#2
Ok, pasted inside of function simplenews_mail_mail simple call to mail function like this:
<?php
function simplenews_mail_mail($nid, $vid, $mail, $key = 'node') {
// Get subscription data for recipient and language
$account = new stdClass();
$account->mail = $mail;
$subscription = simplenews_get_subscription($account);
$params['context']['account'] = $subscription;
// Get node data for the mail
$node = node_load($nid, $vid);
if (is_object($node)) {
$params['from'] = _simplenews_set_from($node);
$params['context']['newsletter'] = taxonomy_get_term($node->simplenews['tid']);
$params['context']['node'] = $node;
// Send mail
if (module_exists('mimemail')) {
// If mimemail module is installed ALL emails are send via this module.
// drupal_mail() builds the content of the email but does NOT send.
$message = drupal_mail('simplenews', $key, $subscription->mail, $subscription->language, $params, $params['from']['formatted'], FALSE);
$plain = $message['params']['context']['node']->simplenews['s_format'] == 'plain';
$message['result'] = mimemail(
$message['from'],
$message['to'],
$message['subject'],
$message['body'],
$plain,
$message['headers'],
$plain ? $message['body'] : simplenews_html_to_text($message['body'], TRUE),
isset($message['params']['context']['node']->files) ? $message['params']['context']['node']->files : array(),
''
);
}
else {
$message = drupal_mail('simplenews', $key, $subscription->mail, $subscription->language, $params, $params['from']['address'], TRUE);
}
// ================================================
// ------- here is my string -------------------------------
mail('recipient@mail.ru', 'Hello', 'It works', 'From: supp@my-domain.ru');
// ------------ end ------------------------------------
// ================================================
// Log sent message.
if (variable_get('simplenews_debug', FALSE)) {
if (module_exists('mimemail')) {
$via_mimemail = t('Sent via Mime Mail');
}
//TODO Add line break before %mimemail.
if ($message['result']) {
watchdog('simplenews', 'Outgoing email. Message type: %type<br />Subject: %subject<br />Recipient: %to %mimemail<br />From: %from', array('%type' => $key, '%to' => $message['to'], '%subject' => $message['subject'], '%mimemail' => $via_mimemail, '%from' => $params['from']['address']), WATCHDOG_DEBUG);
}
else {
watchdog('simplenews', 'Outgoing email failed. Message type: %type<br />Subject: %subject<br />Recipient: %to %mimemail', array('%type' => $key, '%to' => $message['to'], '%subject' => $message['subject'], '%mimemail' => $via_mimemail), WATCHDOG_ERROR);
}
}
}
else {
watchdog('simplenews', 'Newsletter not send: node does not exist (nid = @nid; vid = @vid).', array('@nid' => $message['nid'], '@vid' => $message['vid']), WATCHDOG_ERROR);
}
return isset($message['result']) ? $message['result'] : FALSE;
}
?>
and the letter with "hello" is in the mailbox.
So the problem is with drupal_mail function and parameters passed to it.
#3
Finally I got the cause of trouble. It was the header From: which is defined in hook simplenews_mail() and was set as follow:
$headers['From'] = $params['from']['formatted'];
I changed it like this:
$headers['From'] = $params['from']['address'];
And the letter finally was delivered to mailbox.
There is such notice about formatted header on the PHP manual pages but only about windows and in the phpinfo() on my hosting I see Linux vip-14 2.6.25-NX.17-vip-14 #2 SMP but have the same problem
#4
Very nice that you have found a cause of your problem. But could you pls digg deeper to help us all. I have no intention to replace the formatted from (me@example.com) by the address (me@example.com) in simplenews. The real cause must lie in some special characters or faulty encription. Please help by searching for the root of the cause which we can tackle in code.
#5
I'm probably experiencing a related issue. When using SimpleNews with Mime Mail, the SMTP server rejects the newsletter email message because there's broken email address in MAIL FROM command. Somehow when using Mime Mail, the $params['from']['formatted'] (see #3) ends to the from address used as a parameter for MAIL FROM command. It clearly should be the $params['from']['address'].
When the MIME Mail is disabled there's no problem.
edit:
This is what SMTP-server receives:
MAIL FROM:<"John Doe" <john.doe@some.domain>>This is what it should be:
MAIL FROM:<john.doe@some.domain>Just like the the address is processed twice or something, since there's duplicate <>
edit2:
Just found out, that explicitly setting $headers['From'] to a valid email address before mimemail() is called in simplenews_mail_mail() clears the problem?? It seems whatever is set to $headers['From'], it is passed to MAIL FROM -parameter when MIME Mail sends the message using PHP mail(). The $headers['From'] seems to contain the "From name" by default, as set in newsletter settings.
edit3: Oh crap... I was missing the sendmail_from setting in php.ini. I don't usually do development using Windows machines, and now there's one more reason not to do so. Cannot understand why lacking this setting would cause this behaviour.
#6
Recieved email from okaalto:
-----------------------------------------------------------------------------
This whole episode happened in Windows environment. I think that the sendmail_from setting in php.ini is actually mandatory in Windows systems, in order to send any mail using php. So, adding that setting cleared the problem. There's a good comment in PHP.net explaining mail() function and its relation to from-address used with SMTP.
http://fi2.php.net/manual/en/function.mail.php#72715
The actual error was that the SMTP-server was sent a broken MAIL FROM -command, as I stated in http://drupal.org/node/469880#comment-2090758
This happened only when MIME Mail module was also in use. I was unable to isolate the module actually causing this. I only managed to verify the problem from the SMTP-protocol trace between the mail server and Windows machine.
I think we could consider this issue resolved since problem occurs only when there is essential setting missing in the configuration.
------------------------------------------------------------------------------
Based on this I will close the issue.
captaindav
http://drupalanswer.com
#7