troubleshooting bulk email script
| From: | Redmond Militante | Date: | Fri, 05 Nov 2004 18:37:00 +0000 |
| Subject: | troubleshooting bulk email script | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-201300@lists.php.net to get a copy of this message | ||
hi
i have a script that loops through a mysql database, and extracts usernames and email addresses,
then uses this information to send emails
the code for the (i think) relevant part of the script is below. i'm having a couple of
problems with this script -
the main one being that bulk email messages seem to get 'cut off' at a certain point in
the message. for ex., a message that is 3 paragraphs long arrives at the recipient with the last
paragraph cut off. the problem seems to be random, and doesn't seem to have a relation to how
many email addresses you happen to be sending to at a particular time. it does, i think have
something to do with cutting and pasting text into my email sender form from microsoft word. the
problem also seems to be sporadic - i.e., i have a hard time reproducing it, but my users don't
seem to have any trouble.
another problem i have is weird characters showing up like '\222' or '\224' in
the body of the email when text is cut and pasted from microsoft word. this is not as big of a
problem as the emails getting cut off. i'm pasting the mail() loop from the script below, if
anyone has any suggestions. it's really hard to troubleshoot this one since i'm not sure
if it has to do with the number of emails that are being sent out at once. i only have a limited
number of test email recipient accounts, the rest in the database are all real emails that i
wouldn't want to send test emails to.
thanks for any suggestions, code is below:
$sql = "select * from table where name=... order by id";
//Query for the total number of rows
$getTotalRows = mysql_query($sql, $conn);
$totalRowsNum = mysql_num_rows($getTotalRows);
//Append the limit and offset to the sql
$sql.=" Limit ".$_GET['thisOffset'].",$recordLimit";
//Query and fetch array with the limit and offset
$query = mysql_query($sql, $conn);
while ($result=mysql_fetch_array($query)){
//Increment the line index by 1
$_GET['lineIndex']++;
if (floor($_GET['lineIndex']/2) == ($_GET['lineIndex']/2))
{
echo "<div align=center><br>";
$userid=$result['userid'];
$firstname=$result['firstname'];
$middlename=$result['middlename'];
$lastname=$result['lastname'];
$address1=$result['address1'];
$address2=$result['address2'];
$address3=$result['address3'];
$city=$result['city'];
$state=$result['state'];
$zip=$result['zip'];
$country=$result['country'];
$phone1=$result['phone1'];
$phone2=$result['phone2'];
$email=$result['email'];
$dateregistered=$result['dateregistered'];
$letters_sent=$result['letters_sent'];
$status=$result['status'];
$to = "\"$lastname, $firstname $middlename\" <$email>";
$from = "\"".$_REQUEST['str_from_name']."\"
<".$_REQUEST['str_from_email'].">";
$to = str_replace("\\'", "'", $to);
$from = str_replace("\\'", "'", $from);
$_REQUEST['str_subject'] = str_replace("\\'", "'",
$_REQUEST['str_subject']);
//$message = str_replace("\\\\\'", "'",
$_REQUEST['str_message']);
$message = $str_message;
mail($to, $_REQUEST['str_subject'], $message, "From: $from\nX-Mailer:
System33r");
--
Redmond Militante
Software Engineer / Medill School of Journalism
FreeBSD 5.2.1-RELEASE-p10 #0: Wed Sep 29 17:17:49 CDT 2004 i386
12:15PM up 2 days, 21:22, 1 user, load averages: 0.02, 0.05, 0.02