mail() sends copy to return path without provocation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jeremycellis
Forum Newbie
Posts: 1
Joined: Wed Aug 08, 2007 7:17 am

mail() sends copy to return path without provocation

Post by jeremycellis »

Hello—

I tried a search through the forums but didn't come up with anything, however, I'm not exactly sure how to describe this problem in a few keywords, either. So if any of you know of better keywords, or know this has been discussed/solved before, just let me know.

Here's the situation:

When I use mail() [and yes, I saw all about SwiftMail, and at this time, I'm not interested. ;-)] to send e-mails I am receiving a copy of the mail at the specified return path. I do not want this to happen, as sometimes I am mailing over a hundred people (not spam, it is a mailing that people have signed up for, a club for nerdy words).

This only started happening which I changed the return address from just the address "nerdywordclub@nerdywordclub.com" to "'The Nerdy Word Club' <nerdywordclub@nerdywordclub.com>"

Here's the code:

Code: Select all

<?php
  require "includes/functions.inc";
  $webmaster = '"The Nerdy Word Club" <nerdywordclub@nerdywordclub.com>';
  $message = "Good Morning. This is the daily mailing of the Nerdy Word Club.\n\n";
  $message = $message . "And now for the word:\n\n";
  $message = $message . "--------------------------------------------------\n\n";
  $query = "SELECT date, username, word, function, definition, name_id FROM words NATURAL JOIN names WHERE date = \"$date\" ORDER BY date ASC";
  $result = mysql_query ($query, $connection);
  while ($row = mysql_fetch_row($result)) {
    $date = "$row[0]";
    ereg($date_pattern, $date, $date_parts);
    $date = mktime(0, 0, 0, $date_parts[2], $date_parts[3], $date_parts[1]);
    $result2 = mysql_query ("SELECT COUNT(word) FROM words WHERE date <= \"$row[0]\" AND name_id = \"$row[5]\"", $connection);
    $row2 = mysql_fetch_row($result2);
    $count = $row2[0];
    $message = $message . date('d F Y', $date) . " ($row[1] -- $count words)\n";
    $message = $message . "$row[2] [$row[3]]\n";
    $message = $message . "$row[4]\n\n";
  }
  $message = $message . "--------------------------------------------------\n\n";
  $message = $message . "Would you like to receive these mailings on a weekly or monthly basis instead? Or would you like to stop receiving these mailings all together? Or maybe you've got a word you're itching to submit? Login to do all these things.\n\n";
  $message = $message . "http://nerdywordclub.com/login.php\n";
  $message2 = "Password: [hidden for your security]\n\n";
  $message2 = $message2 . "And don't forget, you can now purchase Nerdy Word Club t-shirts! Show off your nerdy pride: http://nerdywordclub.com/merchandise.php\n\n";
  $message2 = $message2 . "See you next time,\n";
  $message2 = $message2 . "Jeremy C. Ellis\n";
  $message2 = $message2 . "$webmaster\n";
  $message2 = $message2 . "http://nerdywordclub.com\n";
  $headers = "From: $webmaster\n";
  $headers = $headers . "X-Sender: $webmaster\n";
  $headers = $headers . "X-Priority: 3\n";
  $headers = $headers . "Return-Path: $webmaster\n";
  $headers = $headers . "X-Mailer: PHP\r\n";
  $result = mysql_query ("SELECT username, email FROM names WHERE subscription = 'D'", $connection);
  while ($row = mysql_fetch_row($result)) {
    $user = $row[0];
    $recipient = $row[1];
    mail($recipient, "Daily Word from the Nerdy Word Club", $message . "Username: $user\n" . $message2, $headers, "-f$webmaster");
  }
?>
I've done some preliminary testing and if switch the declaration of $webmaster back to just "nerdywordclub@nerdywordclub.com" I don't receive a duplicate of the e-mail.

Thanks for any help!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

I've had a somewhat similar issue, so I'm interested in what others contribute to this, but I did notice that in your declaration of $webmaster, that string includes double quotes around the alias name, then when you execute the mail() function at the end, you enclose the string in double quotes, i.e., "-f$webmaster", so maybe there's a conflict there, and might explain why there's no problem when you omit the alias name. ???
Post Reply