trying to track down this problem has been a chore. basically, here is my situation:

I am using Subscriptions, I want new users to receive a message anytime a new forum post is created. I have my mail template and subscriptions set up. However, when ever I run cron, I get the message: Unable to send e-mail. Contact the site administrator if the problem persists.

Actually, the problem occurs with all emails sent from the site, including new user registrations.
I have uninstalled subsciptions, leaving Mail Editor, I still get the problem. The problem only goes away when I disable Mail Editor. I tried uninstalling, clearing cache, checking the DB that the tables for mail editor are gone (they are). I try registering a new user, no problem, mail goes through.

Once I install Mail Editor, the problem comes back. In watch dog, I get Error sending email.

Any brilliant ideas?

** Edit **
I have just tried the current dev release, same problem.
I tested the Beta2 on a separate site with minimal modules (and nothing that touches email), and I get the same error when I run cron. This time, I tested only by registering a new user. The new user never receives a welcome email or confirmation that the account is activated (both templates were set up in Mail Editor).

Again, thank you for your help.

** Edit **
Further investigation on my test install. Right now I have Mail templates activated for

  • User - register_pending_approval_admin
  • User - status_activated

When I register an account now, I receive the following 2 errors.

  1. Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in DefaultMailSystem->mail() (line 76 of ...system.mail.inc
  2. Unable to send e-mail. Contact the site administrator if the problem persists.

this is with Beta2 installed. So I feel like maybe system.mail.inc is not receiving the proper inputs or they aren't formatted as it expects.

Thank you so much for the help!

CommentFileSizeAuthor
#16 mail_edit-1488896-16.patch689 bytesles lim

Comments

scottsawyer’s picture

Issue summary: View changes

** Edit - 2012-03-18 5:23pm EST **

salvis’s picture

Please install and enable the Devel module and enable its Traceback Error Handler to find out what parameters are passed to mail().

scottsawyer’s picture

Hello salvis,

I was hoping you'd catch on to my issue, I appreciate how attentive you are to the queues.

I have installed Devel, enabled backtrace, and went through the process of creating a new account where there should have been an email generated.

I am still receiving the same error "Unable to send e-mail." I am not seeing any additional information about what is being sent to mail(). Should this info be displayed on screen? I checked the log, and it seems that I get the same mail error -

Type	mail
Date	Monday, March 19, 2012 - 09:35
User	scottsawyer
Location	http://www.scottsawyerconsulting.net/admin/people/create
Referrer	http://www.scottsawyerconsulting.net/admin/people/create
Message	Error sending e-mail (from scott@scottsawyerconsulting.com to scottsawyer.consulting@gmail.com).
Severity	error

Not sure why this one doesn't have a 'to' entry in the message.

Type	mail
Date	Monday, March 19, 2012 - 09:50
User	Anonymous (not verified)
Location	http://www.scottsawyerconsulting.net/user/register
Referrer	http://www.scottsawyerconsulting.net/user/register
Message	Error sending e-mail (from scott@scottsawyerconsulting.com to ).
Severity	error

Is this what you were looking for? Some how I feel like you wanted Devel to out put something on my screen, which it is not.

Further, not sure how this might help or hurt, in mail_edit_alter.inc, I uncommented lines 99, 100

dpm($message, 'drupal_mail() is disabled in _mail_edit_mail_alter(), this would be sent');
  $message['to'] = '';

I was hoping this would give me something to look at, but it doesn't show on my screen.

Thanks again for your help. Let me know how to get the info you need.

** EDIT **

I spoke too soon, I actually do get the output:

    drupal_mail() is disabled in _mail_edit_mail_alter(), this would be sent =>
        ... (Array, 11 elements)
        Krumo version 0.2.1a
        | http://krumo.sourceforge.net
<blockquote>
        Called from /home/content/s/s/a/ssawyer408/html/sites/all/modules/contributed/mail_edit/mail_edit.alter.inc, line 99  
</blockquote>
    A confirmation request to cancel your account has been sent to your e-mail address.

So, what this looks like is the $message['to'] is not present. I will further test and see if I can find out what happened to my "to" val.

salvis’s picture

Try clicking on the ... (Array, 11 elements) line, it should expand dynamically (there are situations where it doesn't work though, unfortunately).

I am still receiving the same error "Unable to send e-mail." I am not seeing any additional information about what is being sent to mail(). Should this info be displayed on screen?

Yes, you should see it on the screen. However, it's only displayed when the current user has the 'view Devel information' (or something like that) permission.

The additional info will not be displayed for the "Unable to send e-mail." message but for "Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in DefaultMailSystem->mail() (line 76 of ...system.mail.inc"

Enable all Backtrace options, to maximize the chances of at least one getting through.

The debug code that you uncommented deliberately sets $message['to'] = ''; to kill the outgoing message (while debugging). Don't forget to comment that out again. (I sure hope we're not seeing a case where someone enabled that debug helper and forgot to disable it afterwards.)

scottsawyer’s picture

Hey Salvis,

Thanks so much for the continued help with this. I uncommented those lines, not to worry. I have been going through all of the array values of $message.

Here is the output of the array:

    drupal_mail() is disabled in _mail_edit_mail_alter(), this would be sent - Array =>
        ... (Array, 11 elements)
            id (String, 21 characters ) user_status_activated
            module (String, 4 characters ) user
            key (String, 16 characters ) status_activated
            to (String, 32 characters ) scottsawyer.consulting@gmail.com
            from (String, 31 characters ) scott@scottsawyerconsulting.net
            language (Object) stdClass
                language (String, 2 characters ) en
                name (String, 7 characters ) English
                native (String, 7 characters ) English
                direction (Integer) 0
                enabled (Integer) 1
                plurals (Integer) 0
                formula (String, 0 characters )
                domain (String, 0 characters )
                prefix (String, 0 characters )
                weight (Integer) 0
                javascript (String, 0 characters )
            params (Array, 1 element)
            send (Boolean) TRUE
            subject (String, 71 characters ) Account details for ssawyer408 at ScottSawyerCo...
                Account details for ssawyer408 at ScottSawyerConsulting.NET (approved)
            body (Array, 1 element)
                0 (String, 592 characters ) ssawyer408, Your account at ScottSawyerConsu...
                    ssawyer408, Your account at ScottSawyerConsulting.NET has been activated. You may now log in by clicking this link or copying and pasting it into your browser: http://www.scottsawyerconsulting.net/user/reset/57/1332189742/mjBvPmtU8j2wjr0QJFAdL5azNrIl5UXm2wl1zh8xNRk This link can only be used once to log in and will lead you to a page where you can set your password. After setting your password, you will be able to log in at http://www.scottsawyerconsulting.net/user in the future using: username: ssawyer408 password: Your password -- ScottSawyerConsulting.NET team
            headers (Array, 7 elements)
                MIME-Version (String, 3 characters ) 1.0
                Content-Type (String, 51 characters ) text/plain; charset=UTF-8; format=flowed; delsp...
                Content-Transfer-Encoding (String, 4 characters ) 8Bit
                X-Mailer (String, 6 characters ) Drupal
                Return-Path (String, 31 characters ) scott@scottsawyerconsulting.net
                Sender (String, 31 characters ) scott@scottsawyerconsulting.net
                From (String, 31 characters ) scott@scottsawyerconsulting.net

It really feels like this is being thrown by drupal_mail or something, but it's weird that things work when I don't use one of the enabled Mail Editor templates. I have not made any changes to any of the templates, btw.

Did I mention that you rock for the quick responses?

** EDIT **

I added two new dpm()'s to the function _mail_edit_mail_alter()
Directy after the opening '{'

dpm ( $message, 'BEFORE MAIL_ALTER - {$message}' );

Directly before the closing '}'

dpm ( $message, 'AFTER MAIL_ALTER - {$message}' );

Here is my result:

BEFORE MAIL_ALTER - Array =>

    ... (Array, 11 elements)
        id (String, 21 characters ) user_status_activated
        module (String, 4 characters ) user
        key (String, 16 characters ) status_activated
        to (String, 32 characters ) scottsawyer.consulting@gmail.com
        from (String, 31 characters ) scott@scottsawyerconsulting.net
        language (Object) stdClass
            language (String, 2 characters ) en
            name (String, 7 characters ) English
            native (String, 7 characters ) English
            direction (Integer) 0
            enabled (Integer) 1
            plurals (Integer) 0
            formula (String, 0 characters )
            domain (String, 0 characters )
            prefix (String, 0 characters )
            weight (Integer) 0
            javascript (String, 0 characters )
        params (Array, 1 element)
            account (Object) stdClass
        send (Boolean) TRUE
        subject (String, 70 characters ) Account details for ssawyer408 at ScottSawyerCo...
        body (Array, 1 element)
            0 (String, 577 characters ) ssawyer408, Your account at ScottSawyerConsult...
                ssawyer408, Your account at ScottSawyerConsulting.NET has been activated. You may now log in by clicking this link or copying and pasting it into your browser: http://www.scottsawyerconsulting.net/user/reset/57/1332191575/OkVMGyrZXrwWljT4km_6WqGgUSnb_YTV1l0h1isHXi0 This link can only be used once to log in and will lead you to a page where you can set your password. After setting your password, you will be able to log in at http://www.scottsawyerconsulting.net/user in the future using: username: ssawyer408 password: Your password -- ScottSawyerConsulting.NET team
        headers (Array, 7 elements)
            MIME-Version (String, 3 characters ) 1.0
            Content-Type (String, 51 characters ) text/plain; charset=UTF-8; format=flowed; delsp...
                text/plain; charset=UTF-8; format=flowed; delsp=yes
            Content-Transfer-Encoding (String, 4 characters ) 8Bit
            X-Mailer (String, 6 characters ) Drupal
            Return-Path (String, 31 characters ) scott@scottsawyerconsulting.net
            Sender (String, 31 characters ) scott@scottsawyerconsulting.net
            From (String, 31 characters ) scott@scottsawyerconsulting.net
    Krumo version 0.2.1a
    | http://krumo.sourceforge.net
    Called from /home/content/s/s/a/ssawyer408/html/sites/all/modules/contributed/mail_edit/mail_edit.alter.inc, line 71  

AFTER MAIL_ALTER - Array =>

    ... (Array, 11 elements)
        id (String, 21 characters ) user_status_activated
        module (String, 4 characters ) user
        key (String, 16 characters ) status_activated
        to (String, 32 characters ) scottsawyer.consulting@gmail.com
        from (String, 31 characters ) scott@scottsawyerconsulting.net
        language (Object) stdClass
            language (String, 2 characters ) en
            name (String, 7 characters ) English
            native (String, 7 characters ) English
            direction (Integer) 0
            enabled (Integer) 1
            plurals (Integer) 0
            formula (String, 0 characters )
            domain (String, 0 characters )
            prefix (String, 0 characters )
            weight (Integer) 0
            javascript (String, 0 characters )
        params (Array, 1 element)
            account (Object) stdClass
                uid (String, 2 characters ) 57
                name (String, 10 characters ) ssawyer408
                pass (String, 55 characters ) $S$Da1/by63bP3tqjDT9A41PdQgnq414tRqpqOXIXCTWt7q...
                mail (String, 32 characters ) scottsawyer.consulting@gmail.com
                theme (String, 0 characters )
                signature (String, 0 characters )
                signature_format (String, 13 characters ) filtered_html
                created (String, 10 characters ) 1332184576
                access (String, 1 characters ) 0
                login (String, 1 characters ) 0
                status (Integer) 1
                timezone (String, 16 characters ) America/New_York
                language (String, 0 characters )
                picture (Integer) 0
                init (String, 32 characters ) scottsawyer.consulting@gmail.com
                data (Array, 9 elements)
                    contact (Integer) 1
                    ckeditor_default (String, 1 characters ) t | (Callback) t();
                    ckeditor_show_toggle (String, 1 characters ) t | (Callback) t();
                    ckeditor_popup (String, 1 characters ) f
                    ckeditor_skin (String, 4 characters ) kama
                    ckeditor_expand (String, 1 characters ) t | (Callback) t();
                    ckeditor_width (String, 4 characters ) 100%
                    ckeditor_lang (String, 2 characters ) en
                    ckeditor_auto_lang (String, 1 characters ) t | (Callback) t();
                roles (Array, 1 element)
                    2 (String, 18 characters ) authenticated user
                rdf_mapping (Array, 3 elements)
                    rdftype (Array, 1 element)
                        0 (String, 16 characters ) sioc:UserAccount
                    name (Array, 1 element)
                    homepage (Array, 2 elements)
                original (Object) stdClass
                    uid (String, 2 characters ) 57
                    name (String, 10 characters ) ssawyer408
                    pass (String, 55 characters ) $S$Da1/by63bP3tqjDT9A41PdQgnq414tRqpqOXIXCTWt7q...
                    mail (String, 32 characters ) scottsawyer.consulting@gmail.com
                    theme (String, 0 characters )
                    signature (String, 0 characters )
                    signature_format (String, 13 characters ) filtered_html
                    created (String, 10 characters ) 1332184576
                    access (String, 1 characters ) 0
                    login (String, 1 characters ) 0
                    status (String, 1 characters ) 0
                    timezone (String, 16 characters ) America/New_York
                    language (String, 0 characters )
                    picture (NULL)
                    init (String, 32 characters ) scottsawyer.consulting@gmail.com
                    data (Array, 9 elements)
                    roles (Array, 1 element)
                    rdf_mapping (Array, 3 elements)
                is_new (Boolean) FALSE
        send (Boolean) TRUE
        subject (String, 71 characters ) Account details for ssawyer408 at ScottSawyerCo...
            Account details for ssawyer408 at ScottSawyerConsulting.NET (approved)
        body (Array, 1 element)
            0 (String, 592 characters ) ssawyer408, Your account at ScottSawyerConsu...
                ssawyer408, Your account at ScottSawyerConsulting.NET has been activated. You may now log in by clicking this link or copying and pasting it into your browser: http://www.scottsawyerconsulting.net/user/reset/57/1332191575/OkVMGyrZXrwWljT4km_6WqGgUSnb_YTV1l0h1isHXi0 This link can only be used once to log in and will lead you to a page where you can set your password. After setting your password, you will be able to log in at http://www.scottsawyerconsulting.net/user in the future using: username: ssawyer408 password: Your password -- ScottSawyerConsulting.NET team
        headers (Array, 7 elements)
            MIME-Version (String, 3 characters ) 1.0
            Content-Type (String, 51 characters ) text/plain; charset=UTF-8; format=flowed; delsp...
                text/plain; charset=UTF-8; format=flowed; delsp=yes
            Content-Transfer-Encoding (String, 4 characters ) 8Bit
            X-Mailer (String, 6 characters ) Drupal
            Return-Path (String, 31 characters ) scott@scottsawyerconsulting.net
            Sender (String, 31 characters ) scott@scottsawyerconsulting.net
            From (String, 31 characters ) scott@scottsawyerconsulting.net
    Krumo version 0.2.1a
    | http://krumo.sourceforge.net
    Called from /home/content/s/s/a/ssawyer408/html/sites/all/modules/contributed/mail_edit/mail_edit.alter.inc, line 108  

The only differences I noticed is that the body[0] went from 577 chars, to 592, even though the body text is identical. Do you think there could be some trailing white space or something that may cause the mail function to choke?

salvis’s picture

Did I mention that you rock for the quick responses?

Thank you — quickly-responding serious testers are very motivating! :)

Hmm, 15 characters more. We may be replacing LF with CR/LF. Do we have 15 lines in the message?

The subject gained one character, too. Now THAT is disturbing! If we added a control character at the end of the subject, that could cause subsequent mail header lines (which might include the To header) to be ignored, actually seen as part of the body.

Try saving the subject at the top in a helper variable and restoring it at the end.

On what platform/operating system are you running?

scottsawyer’s picture

Both of the sites are on Godaddy shared hosts. I know all the issues, but I assure you, I am sending mail just fine when this module is not envoked. I don't have any other mail modules installed on my test install, though, on the (soon to be) production install, I am using Subscriptions (great module, btw).

Ok, I've been trying a lot of different things with the subject

I created a variable $helpersubject = $message['subject']
Then, at the end, set $message['subject'] = $helpersubject

500 error.

I commented out the line

$message['subject'] = drupal_html_to_text(mail_edit_format($template['subject'], $data, $options));

replaced with:

$message['subject'] = drupal_html_to_text($helpersubject);

I still get 70 chars on the initial dpm, 71 at the end.

I tried commenting out the entire line

$message['subject'] = drupal_html_to_text(mail_edit_format($template['subject'], $data, $options));

500 error.

I think you are exactly right about the 15 lines, in the Mail Editor template for status_activated, there are 16 lines, or 15 line returns.

SO, that could be happening to my subject.

salvis’s picture

That is really nasty! There's nothing we can do, really, if you can't even do simple assignments.

Maybe try

$message['subject'] = 'TEST SUBJECT';

$message['subject'] = drupal_html_to_text($helpersubject);

I still get 70 chars on the initial dpm, 71 at the end.

It sure would be interesting to find out what that extraneous character is...

Try something like

$translated = drupal_html_to_text($helpersubject);
dpm(ord($translated[strlen($translated) - 2]));
dpm(ord($translated[strlen($translated) - 1]));
$translated = substr($translated, 0, strlen($translated) - 1);
$message['subject'] = $translated;
scottsawyer’s picture

$message['subject'] = "Test Subject"

500 error.

If I comment out all of the lines for $message['subject']: 500 error.

It seems to me that if I commented all of the $message['subject'], it would just pass what ever the default $message['subject'] to the drupal_mail function, right?

Something I tried was setting :

$helpersubject['subject'] = $message['subject'];

Then I did:

$message['subject'] = drupal_html_to_text($helpersubject['subject']);

This doesn't give 500, but it still returns 71 chars.

Working on some regex to try and remove any cr and lf. So far, not winners.

I will test the code you recommend in about 30 minutes. Family stuff.

I really appreciate you staying with me on this, I have to give my client a progress report in the morning. We are so close on this project, I just need to be able to get these subscriptions out to the members.

scottsawyer’s picture

Tested this code:

$helpersubject = $message['subject'];
$translated = drupal_html_to_text($helpersubject);
dpm(ord($translated[strlen($translated) - 2]));
dpm(ord($translated[strlen($translated) - 1]));
$translated = substr($translated, 0, strlen($translated) - 1);
$message['subject'] = $translated;	

Returns 500

Tried an alternate I've been playing with

$helpersubject['subject'] = $message['subject'];
$translated = drupal_html_to_text($helpersubject['subject']);
dpm(ord($translated[strlen($translated) - 2]));
dpm(ord($translated[strlen($translated) - 1]));
$translated = substr($translated, 0, strlen($translated) - 1);
$message['subject'] = $translated;	

Returns

Notice: Array to string conversion in strlen() (line 1600 of /home/content/s/s/a/ssawyer408/html/includes/bootstrap.inc). =>

    ... (Array, 20 elements)
    Krumo version 0.2.1a
    | http://krumo.sourceforge.net
     

Warning: preg_match() expects parameter 2 to be string, array given in preg_match() (line 1606 of /home/content/s/s/a/ssawyer408/html/includes/bootstrap.inc). =>

    ... (Array, 20 elements)
    Krumo version 0.2.1a
    | http://krumo.sourceforge.net
     


Fatal error: Cannot unset string offsets in /home/content/s/s/a/ssawyer408/html/sites/all/modules/contributed/devel/krumo/class.krumo.php on line 610

So... what it is looking like is $message['subject'] is actually an array???

Starting all the way over with my original assignment:

$helpersubject = $message['subject'];
dpm ($helpersubject, "Helper - {$helpersubject}");

Returns:

Helper - Account details for ssawyer408 at ScottSawyerConsulting.NET (approved) => Account details for ssawyer408 at ScottSawyerConsulting.NET (approved)

So it looks like $message['subject'] is something like

$message['subject']  = array('Account details for ssawyer408 at ScottSawyerConsulting.NET (approved)' => 'Account details for ssawyer408 at ScottSawyerConsulting.NET (approved)');

Which isn't what I would have expected.

I will try doing all the string functions on both the $key and $val of the $message['subject'] array, then reassign.

I'll be back...

** EDIT **

Just a quick update.

It seems that if I attempt to set $message['subject'] in any way, the very last manipulation must be drupal_html_to_text($something);

Even if I attempt to set $message['subject'] = $message['subject'], or not set $message['subject'] at all, I get a 500 Internal Server Error.

I am fairly certain drupal_html_to_text is adding some lf or cr and causing the email to not send.

... Some time later...
I just tried this again, removing all references to $message['subject'], dpm, variable assignments, templates, everything.
Well, the message goes through, at least on my test site, and only on one of the built-in User templates, (on new user activation).

I am still at a loss as to why I can't seem to successfully set a $message['subject'] in _mail_edit_mail_alter(). And I am afraid that on my customer's site, where we are using Email Editor to send Subscription notifications to our users, we will wind up sending messages with no subject at all, or worse, it will not send without a subject...

I guess that will be my next comment.

I really want to thank you again for your help thus far, and hope you stick with me until we get some sort of acceptable solution.

scottsawyer’s picture

Well, partial victory. On my customer's site, I added my modified version of mail_edit_alter.inc with all references to $message['subject'] removed, and the Subscriptions notifications get through, only no subjects are included in the emails.

So, at least we have that.

I am going to spend some more time with this, as sending email with no subject is not really acceptable.

salvis, if you have any more great ideas, I am all ears.

salvis’s picture

At this point I'm convinced that this is a bug in the PHP version which is installed in your Godaddy account. Just move away from Godaddy.

If your "customer's site" is on a different host, it would probably have worked from the start...

scottsawyer’s picture

Hey salvis,

You might be very well correct. Changing hosts isn't really an option at this point. As with most Drupalers, I have had my fair share of experience with Godaddy, but at the end of the day, they are one of the biggest hosting companies, their prices are really low (I know, you get what you pay for :), and I have only, on very - VERY rare occassion run into a problem that just boiled down to no solution available.

I may have mentioned that I felt like drupal_html_to_text was breaking the subject (thanks in no small part to your insights), so I had the idea to rewrite that function, and only call my new function on the $message['subject'].

So, my _mail_edit_mail_alter looks like this: (note the comments around $message['subject']

/**
 * Implements hook_mail_alter().
 *
 * @param array $message
 */
function _mail_edit_mail_alter(array &$message) {

  if (!$template = _mail_edit_load($message['id'], $message['language'])) {
    return;
  }

  $data = (isset($message['params']['data']) ? $message['params']['data'] : $message['params']);
  $data['template'] = $template;
  if (isset($message['params']['account']) && !isset($data['user'])) {
    $data['user'] = $message['params']['account'];
  }
  $options = array(
    'language' => $message['language'],
    'clear'    => TRUE,
  );
  if ($message['module'] == 'user') {
    $options['callback'] = 'user_mail_tokens';
  }

/*  
 * 2012-03-21 - edit - SSC
 * This is the original call to the $message['subject']  
 * it was removed because it was causing errors.
 * the thought is that something with drupal_html_to_text added a lf or cr
 * $message['subject'] = drupal_html_to_text(mail_edit_format($template['subject'], $data, $options));
*/
  $message['subject'] = mail_edit_html_to_text(mail_edit_format($template['subject'], $data, $options));

  $args = array($template['body'], $data, $options);
  if (isset($message['params']['context']['mail_edit'])) {
    $args[] = $message['params']['context']['mail_edit'];
  }
  $body = call_user_func_array('mail_edit_format', $args);
  // Remove trailing spaces because these may be interpreted as soft line
  // breaks by the email client.
  $message['body'] = array(preg_replace('/ +(\r?\n)/', '\\1', $body));
  
  /* Uncomment this line for debugging...*/

}

And the companion function mail_edit_html_to_text (placed in the same file mail_edit_alter.inc


/** 
 * replacement function for
 * drupal_html_to_text
 * because our subject is choking on the one that comes 
 * with drupal
 * 2012-03-21
 */
function mail_edit_html_to_text($string, $allowed_tags = NULL) {
  // Cache list of supported tags.
  static $supported_tags;
  if (empty($supported_tags)) {
    $supported_tags = array('a', 'em', 'i', 'strong', 'b', 'br', 'p', 'blockquote', 'ul', 'ol', 'li', 'dl', 'dt', 'dd', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr');
  }

  // Make sure only supported tags are kept.
  $allowed_tags = isset($allowed_tags) ? array_intersect($supported_tags, $allowed_tags) : $supported_tags;

  // Make sure tags, entities and attributes are well-formed and properly nested.
  $string = _filter_htmlcorrector(filter_xss($string, $allowed_tags));

  // Apply inline styles.
  $string = preg_replace('!</?(em|i)((?> +)[^>]*)?>!i', '/', $string);
  $string = preg_replace('!</?(strong|b)((?> +)[^>]*)?>!i', '*', $string);

  // Replace inline <a> tags with the text of link and a footnote.
  // 'See <a href="http://drupal.org">the Drupal site</a>' becomes
  // 'See the Drupal site [1]' with the URL included as a footnote.
  _drupal_html_to_mail_urls(NULL, TRUE);
  $pattern = '@(<a[^>]+?href="([^"]*)"[^>]*?>(.+?)</a>)@i';
  $string = preg_replace_callback($pattern, '_drupal_html_to_mail_urls', $string);
  $urls = _drupal_html_to_mail_urls();
  $footnotes = '';
  if (count($urls)) {
    $footnotes .= "\n";
    for ($i = 0, $max = count($urls); $i < $max; $i++) {
      $footnotes .= '[' . ($i + 1) . '] ' . $urls[$i] . "\n";
    }
  }

  // Split tags from text.
  $split = preg_split('/<([^>]+?)>/', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
  // Note: PHP ensures the array consists of alternating delimiters and literals
  // and begins and ends with a literal (inserting $null as required).

  $tag = FALSE; // Odd/even counter (tag or no tag)
  $casing = NULL; // Case conversion function
  $output = '';
  $indent = array(); // All current indentation string chunks
  $lists = array(); // Array of counters for opened lists
  foreach ($split as $value) {
    $chunk = NULL; // Holds a string ready to be formatted and output.

    // Process HTML tags (but don't output any literally).
    if ($tag) {
      list($tagname) = explode(' ', strtolower($value), 2);
      switch ($tagname) {
        // List counters
        case 'ul':
          array_unshift($lists, '*');
          break;
        case 'ol':
          array_unshift($lists, 1);
          break;
        case '/ul':
        case '/ol':
          array_shift($lists);
          $chunk = ''; // Ensure blank new-line.
          break;

          // Quotation/list markers, non-fancy headers
        case 'blockquote':
          // Format=flowed indentation cannot be mixed with lists.
          $indent[] = count($lists) ? ' "' : '>';
          break;
        case 'li':
          $indent[] = isset($lists[0]) && is_numeric($lists[0]) ? ' ' . $lists[0]++ . ') ' : ' * ';
          break;
        case 'dd':
          $indent[] = '    ';
          break;
        case 'h3':
          $indent[] = '.... ';
          break;
        case 'h4':
          $indent[] = '.. ';
          break;
        case '/blockquote':
          if (count($lists)) {
            // Append closing quote for inline quotes (immediately).
            $output = rtrim($output, "> \n") . "\"\n";
            $chunk = ''; // Ensure blank new-line.
          }
          // Fall-through
        case '/li':
        case '/dd':
          array_pop($indent);
          break;
        case '/h3':
        case '/h4':
          array_pop($indent);
        case '/h5':
        case '/h6':
          $chunk = ''; // Ensure blank new-line.
          break;

          // Fancy headers
        case 'h1':
          $indent[] = '======== ';
          $casing = 'drupal_strtoupper';
          break;
        case 'h2':
          $indent[] = '-------- ';
          $casing = 'drupal_strtoupper';
          break;
        case '/h1':
        case '/h2':
          $casing = NULL;
          // Pad the line with dashes.
          $output = _drupal_html_to_text_pad($output, ($tagname == '/h1') ? '=' : '-', ' ');
          array_pop($indent);
          $chunk = ''; // Ensure blank new-line.
          break;

          // Horizontal rulers
        case 'hr':
          // Insert immediately.
          $output .= drupal_wrap_mail('', implode('', $indent)) . "\n";
          $output = _drupal_html_to_text_pad($output, '-');
          break;

          // Paragraphs and definition lists
        case '/p':
        case '/dl':
          $chunk = ''; // Ensure blank new-line.
          break;
      }
    }
    // Process blocks of text.
    else {
      // Convert inline HTML text to plain text; not removing line-breaks or
      // white-space, since that breaks newlines when sanitizing plain-text.
      $value = rtrim(decode_entities($value));
      if (drupal_strlen($value)) {
        $chunk = $value;
      }
    }

    // See if there is something waiting to be output.
    if (isset($chunk)) {
      // Apply any necessary case conversion.
      if (isset($casing)) {
        $chunk = $casing($chunk);
      }
      // Format it and apply the current indentation.
      $output .= drupal_wrap_mail($chunk, implode('', $indent));
      // Remove non-quotation markers from indentation.
      $indent = array_map('_drupal_html_to_text_clean', $indent);
    }

    $tag = !$tag;
  }

  return $output . $footnotes;
}

Items that I changed from the original drupal_html_to_text

  1. $value = trim(decode_entities($value)); => $value = rtrim(decode_entities($value)); probably not neccessary, as I think the next item is our curprit
  2. $output .= drupal_wrap_mail($chunk, implode('', $indent)) . MAIL_LINE_ENDINGS; => $output .= drupal_wrap_mail($chunk, implode('', $indent)); Note, I removed the MAIL_LINE_ENDINGS, because this is what added the extra character to our subject, causing everthing to break.

Magically, everything starts working on both of my sites - templates are being parsed, subscriptions are being sent, and I will meet my deadline!

Final note to anyone who is experiencing the aweful Unable to send e-mail. Contact the site administrator if the problem persists., check to see if your function is using drupal_html_to_text, you maybe picking up a line ending that could cause breakage in the drupal_mail.

And a last word to salvis, thank you thank you for your help, and keep up the great work! If you are ever in Atlanta, hit me up, I owe you a beer.

** Now to remember not to break my scripts when I update next....

salvis’s picture

Congratulations for hacking this into shape!

Apparently, there's some ambiguity in this area: #234403: drupal_mail_send() should separate headers with CRLF

What bothers me about Godaddy is that most of your interventions resulted in crashes.

Now that we know what causes the issue, I intend to commit the following change to Mail Editor:

  $message['subject'] = drupal_html_to_text(mail_edit_format($template['subject'], $data, $options));

to

  $message['subject'] = trim(drupal_html_to_text(mail_edit_format($template['subject'], $data, $options)));

(Just add a trim() call.)

Could this work for you?

scottsawyer’s picture

Wow, that is way better than my hack! I am going with your solution. I had actually tried various preg_replace / str_replace / substr expressions and was getting nowhere.

Great job. Thanks again for all the help, never would have solved this with out it!

salvis’s picture

Status: Active » Fixed

You've been pretty determined, too. Thanks for the ride!

Committed to the -dev version.

les lim’s picture

Version: 7.x-1.0-beta2 » 7.x-1.x-dev
Status: Fixed » Needs review
StatusFileSize
new689 bytes

Thanks to both of you for going through all of the above - I was experiencing the same problem on a Pair Networks hosted site, and the trim() resolves it.

The current dev version doesn't have trim() though - it's trying to call strip(), which is undefined.

Patch attached.

salvis’s picture

Status: Needs review » Fixed

Ouch, thanks!

Committed to the -dev version, give it up to 12h to be repackaged.

Status: Fixed » Closed (fixed)

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

rnochezmc’s picture

Project: Mail Editor » User Registration Notification
Version: 7.x-1.x-dev » 7.x-1.0-alpha2
Status: Closed (fixed) » Active

I have a similar issue but with a language translation installed (Spanish). When I use only English (BTW the site is also hosted at Godaddy), there is no problem but when I activate Spanish, I receive the message "Unable to send emil. Contact the site ...". I'm a newbie in Drupal. I installed Drupal in my local development computer and worked fine, I installed it in Bluehost.com and no problem but unfortunatelly my client is with Goddady and I need to make it work.

salvis’s picture

Project: User Registration Notification » Mail Editor
Version: 7.x-1.0-alpha2 » 7.x-1.x-dev
Status: Active » Closed (fixed)

Please don't hijack issues to unrelated projects.

Open a new issue in the other project's queue, and if you think that this thread could help, then post a link to this thread.

salvis’s picture

Issue summary: View changes

** Edit **
Further testing, better info, I hope.