Hi all,

I have recently set up a Drupal website. I am a beginner. My shared host server does not allow nobody@localhost 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.php");
$recipients = $mail;
$headers["To"]      = $mail;
$headers["From"]    = "abc@xyz.org";
$headers["Subject"] = $subject;
$body = str_replace("\n", "\r\n", $message);
$params["host"] = "mail.xyz.org";
$params["port"] = "25";
$params["auth"] = true;
$params["username"] = "abc@xyz.org";
$params["password"] = "defgh";
// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory("smtp", $params);
$mail_object->send($recipients, $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_all('exit', $url);
  header('Location: '. $url);

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

// Mail new password:
    $variables = array('%username' => $account->name, '%site' => variable_get('site_name', 'drupal'), '%password' => $pass, '%uri' => $base_url, '%uri_brief' => substr($base_url, strlen('http://')), '%mailto' => $account->mail, '%date' => format_date(time()), '%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($account->mail, $subject, $body, $headers);

    if ($mail_success) {
      watchdog('user', t('Password mailed to %name at %email.', array('%name' => theme('placeholder', $account->name), '%email' => theme('placeholder', $account->mail))));
      drupal_set_message(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('placeholder', $account->name), '%email' => theme('placeholder', $account->mail))), WATCHDOG_ERROR);
      drupal_set_message(t('Unable to send mail. Please contact the site admin.'));
    }

Comments

splicemix’s picture

that the emails do get through (but often land up in the spam folder).

Nonetheless, receiving the error message on an otherwise blank screen is very annoying! it used to be just a message that "'Your password and further instructions have been sent to your e-mail address.', per ($mail_success)

splicemix’s picture

and I don't get the "headers" error anymore, but I still have the error

"Error mailing password to..."

Advice appreciated. Is it a problem with my headers?

fletcherson’s picture

Pardon me if it sounds confusing, I'll gladly "shorten" it if that's
the case, so please keep me informed.

Look for any trailing space in the PHP. 1 trailing space and you will get that error message.

Open the PHP in an editor and remove any trailing space, the "last bit" has to be this: > (try marking with the mouse and see if any additional empty line after the: > if this is the case remove this line
{> has to be on the last line and last "character/symbol" of the PHP-file})

Hope this helps, it always helped me out:-)

lekei’s picture

I see you were bitten by whitespace before php when using cookies or headers... it happens to everyone "once".

As for mail going to spam:

Your headers must match your server or many spam filters will reject your email. If you look at the tracking code, usually inserted into the message headers in your received mail as a special comment header, it will say "forged headers".

So if your site is www.cafezone.ca, your email must go out with a return address at the domain cafezone.ca (eg. deathpenaltyforspam@cafezone.ca). Also, avoid return addresses like spam@ (or cialis@, for that matter) in the return address.

In addition, make sure that your SPF record is set on your server.
( see: http://www.openspf.org/ )