Problem with sending of password reminder emails

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • splicemix

    #1

    Problem with sending of password reminder emails

    Hi all,

    I have recently set up a Drupal website. I am a beginner. My shared
    host server does not allow nobody@localhos t to send emails, and
    prevents access to php.ini, so I spent some time getting a SMTP script
    running. While the Drupal feedback module and the new account creation
    works fine in terms of sending of mails, I am having some problems with
    the sending of password reminder emails.

    warning: Cannot modify header information - headers already sent by
    (output started at
    /home/affyorg/public_html/cancer/content/mail.php:20) in
    /home/affyorg/public_html/cancer/content/includes/common.inc on line
    192.

    Your advice would be appreciated. Thanks!!

    My mail.php file is as follows:
    <?
    include("Mail.p hp");
    $recipients = $mail;
    $headers["To"] = $mail;
    $headers["From"] = "abc@xyz.or g";
    $headers["Subject"] = $subject;
    $body = str_replace("\n ", "\r\n", $message);
    $params["host"] = "mail.xyz.o rg";
    $params["port"] = "25";
    $params["auth"] = true;
    $params["username"] = "abc@xyz.or g";
    $params["password"] = "defgh";
    // Create the mail object using the Mail::factory method
    $mail_object =& Mail::factory(" smtp", $params);
    $mail_object->send($recipien ts, $headers, $body);
    ?>

    Line 189 - 192 of common.inc is

    // Before the redirect, allow modules to react to the end of the page
    request.
    module_invoke_a ll('exit', $url);

    header('Locatio n: '. $url);

    The Drupal user.module has the following code for password reminders

    // Mail new password:
    $variables = array('%usernam e' => $account->name, '%site' =>
    variable_get('s ite_name', 'drupal'), '%password' => $pass, '%uri' =>
    $base_url, '%uri_brief' => substr($base_ur l, strlen('http://')),
    '%mailto' => $account->mail, '%date' => format_date(tim e()),
    '%login_uri' => url('user', NULL, NULL, TRUE), '%edit_uri' =>
    url('user/'. $account->uid .'/edit', NULL, NULL, TRUE));
    $subject = _user_mail_text ('pass_subject' , $variables);
    $body = _user_mail_text ('pass_body', $variables);
    $headers = "From: $from\nReply-to: $from\nX-Mailer:
    Drupal\nReturn-path: $from\nErrors-to: $from";
    $mail_success = user_mail($acco unt->mail, $subject, $body,
    $headers);

    if ($mail_success) {
    watchdog('user' , t('Password mailed to %name at %email.',
    array('%name' => theme('placehol der', $account->name), '%email' =>
    theme('placehol der', $account->mail))));
    drupal_set_mess age(t('Your password and further instructions have
    been sent to your e-mail address.'));
    }
    else {
    watchdog('user' , t('Error mailing password to %name at %email.',
    array('%name' => theme('placehol der', $account->name), '%email' =>
    theme('placehol der', $account->mail))), WATCHDOG_ERROR) ;
    drupal_set_mess age(t('Unable to send mail. Please contact the
    site admin.'));
    }

  • Jerry Stuckle

    #2
    Re: Problem with sending of password reminder emails

    splicemix wrote:[color=blue]
    > Hi all,
    >
    > I have recently set up a Drupal website. I am a beginner. My shared
    > host server does not allow nobody@localhos t to send emails, and
    > prevents access to php.ini, so I spent some time getting a SMTP script
    > running. While the Drupal feedback module and the new account creation
    > works fine in terms of sending of mails, I am having some problems with
    > the sending of password reminder emails.
    >
    > warning: Cannot modify header information - headers already sent by
    > (output started at
    > /home/affyorg/public_html/cancer/content/mail.php:20) in
    > /home/affyorg/public_html/cancer/content/includes/common.inc on line
    > 192.
    >
    > Your advice would be appreciated. Thanks!!
    >
    > My mail.php file is as follows:
    > <?
    > include("Mail.p hp");
    > $recipients = $mail;
    > $headers["To"] = $mail;
    > $headers["From"] = "abc@xyz.or g";
    > $headers["Subject"] = $subject;
    > $body = str_replace("\n ", "\r\n", $message);
    > $params["host"] = "mail.xyz.o rg";
    > $params["port"] = "25";
    > $params["auth"] = true;
    > $params["username"] = "abc@xyz.or g";
    > $params["password"] = "defgh";
    > // Create the mail object using the Mail::factory method
    > $mail_object =& Mail::factory(" smtp", $params);
    > $mail_object->send($recipien ts, $headers, $body);
    > ?>
    >
    > Line 189 - 192 of common.inc is
    >
    > // Before the redirect, allow modules to react to the end of the page
    > request.
    > module_invoke_a ll('exit', $url);
    >
    > header('Locatio n: '. $url);
    >
    > The Drupal user.module has the following code for password reminders
    >
    > // Mail new password:
    > $variables = array('%usernam e' => $account->name, '%site' =>
    > variable_get('s ite_name', 'drupal'), '%password' => $pass, '%uri' =>
    > $base_url, '%uri_brief' => substr($base_ur l, strlen('http://')),
    > '%mailto' => $account->mail, '%date' => format_date(tim e()),
    > '%login_uri' => url('user', NULL, NULL, TRUE), '%edit_uri' =>
    > url('user/'. $account->uid .'/edit', NULL, NULL, TRUE));
    > $subject = _user_mail_text ('pass_subject' , $variables);
    > $body = _user_mail_text ('pass_body', $variables);
    > $headers = "From: $from\nReply-to: $from\nX-Mailer:
    > Drupal\nReturn-path: $from\nErrors-to: $from";
    > $mail_success = user_mail($acco unt->mail, $subject, $body,
    > $headers);
    >
    > if ($mail_success) {
    > watchdog('user' , t('Password mailed to %name at %email.',
    > array('%name' => theme('placehol der', $account->name), '%email' =>
    > theme('placehol der', $account->mail))));
    > drupal_set_mess age(t('Your password and further instructions have
    > been sent to your e-mail address.'));
    > }
    > else {
    > watchdog('user' , t('Error mailing password to %name at %email.',
    > array('%name' => theme('placehol der', $account->name), '%email' =>
    > theme('placehol der', $account->mail))), WATCHDOG_ERROR) ;
    > drupal_set_mess age(t('Unable to send mail. Please contact the
    > site admin.'));
    > }
    >[/color]

    Like your message says - something on mail.php line 20 caused output to
    be sent the browser. It could be a blank line, for instance.

    Fix that and it should work - or at least go onto the next line.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • splicemix

      #3
      Re: Problem with sending of password reminder emails

      Hmmm. It seems that it was something to do with sending files in
      binary. In any case, thanks! This "header" error is resolved, but I am
      still getting the message "Unable to send mail. Please contact the site
      admin."

      Based on the Drupal code in user.module, this happens when
      ($mail_success) is false. I can't quite see why $mail_success should be
      false, since I do get the password change mail.

      Any advice on how to troubleshoot this would be very welcome!

      Comment

      • Jerry Stuckle

        #4
        Re: Problem with sending of password reminder emails

        splicemix wrote:[color=blue]
        > Hmmm. It seems that it was something to do with sending files in
        > binary. In any case, thanks! This "header" error is resolved, but I am
        > still getting the message "Unable to send mail. Please contact the site
        > admin."
        >
        > Based on the Drupal code in user.module, this happens when
        > ($mail_success) is false. I can't quite see why $mail_success should be
        > false, since I do get the password change mail.
        >
        > Any advice on how to troubleshoot this would be very welcome!
        >[/color]

        Unfortunately, I don't use the Drupal code, and am not familiar with how
        it works. So I'm afraid I can't help you much.

        But I would start by looking at both the mail program's (i.e. sendmail,
        exim, whatever) log to see if there's anything in there.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Meião

          #5
          Re: Problem with sending of password reminder emails

          Look in Drupal's website.
          If you can't find anything, use a Drupal forum, or ask in Drupal
          support.
          They know their code better than we do.

          Comment

          Working...