I have newseltter script that I use to email my customers, but it doesn't seem to work properly anymore. At some point it runs to this weird error: Error: invalid address value on MAIL5->addto() in /home/me123/public_html/nav/sending.php on line 78 OR Error: invalid address value on MAIL5->addto() in /home/me123/public_html/nav/sending.php on line 96 It could be an invalid email in the database but I have over 70k emails and it' really hard to find them. Would be a lot easier to fix the newsletter script. Here is the sending.php file: <?php $expected = array('b', 's', 'o', 't', 'e'); foreach ($_GET as $newkey => $newvalue) { if (in_array($newkey, $expected)) { ${$newkey} = $newvalue; } } $dir = __file__; $dir = str_replace('sending.php', '', $dir); $dir .= 'conn.inc'; $fd = fopen($dir, "r"); while (!feof($fd)) { $buffer = fgets($fd, 4096); $lines[] = $buffer; } fclose($fd); $server = str_replace("\n", '', $lines[0]); $username = str_replace("\n", '', $lines[1]); $password = str_replace("\n", '', $lines[2]); $database = str_replace("\n", '', $lines[3]); $table = str_replace("\n", '', $lines[4]); $email = str_replace("\n", '', $lines[5]); $speed = str_replace("\n", '', $lines[6]); $burst = str_replace("\n", '', $lines[7]); $wheres = str_replace("\n", '', $lines[8]); $switch = str_replace("\n", '', $lines[9]); $username = ENCRYPT_DECRYPT($username); $server = ENCRYPT_DECRYPT($server); $database = ENCRYPT_DECRYPT($database); $password = ENCRYPT_DECRYPT($password); $table = ENCRYPT_DECRYPT($table); $email = ENCRYPT_DECRYPT($email); $wheres = ENCRYPT_DECRYPT($wheres); $switch = ENCRYPT_DECRYPT($switch); $stat = mysql_connect($server, $username, $password); $db = mysql_select_db($database, $stat); if ($wheres) { $numrows = mysql_query('SELECT COUNT(*) FROM '.$table.' WHERE '.$email.'!="" AND '.$wheres.'="'.$switch.'"'); } else { $numrows = mysql_query("SELECT COUNT(*) FROM " . $table . " WHERE " . $email . " !='' "); } $counter = mysql_fetch_array($numrows); $e = $counter[0]; $b = $burst; $s = $speed; $bt = 0; $dir = __file__; $dir = str_replace('nav/sending.php', '', $dir); $dir .= 'nav/'; $myFile = $dir . 'genpre.html'; $fh = fopen($myFile, 'r'); $fullemail = fread($fh, filesize($myFile)); fclose($fh); require_once '../mail/MAIL.php'; while ($bt != $b) { if ($t == 0) { if ($wheres) { $query = mysql_query('SELECT * FROM '.$table.' WHERE '.$email.'!="" AND '.$wheres.'="'.$switch.'" LIMIT 1'); } else { $query = mysql_query("SELECT * FROM " . $table . " WHERE " . $email . "!='' LIMIT 1") or die(mysql_error()); } } else { if ($wheres) { // LINE 78 $query = mysql_query('SELECT * FROM '.$table.' WHERE '.$email.'!="" AND '.$wheres.'="'.$switch.'" LIMIT 1 OFFSET '. $t); } else { $query = mysql_query("SELECT * FROM " . $table . " WHERE " . $email . "!='' LIMIT 1 OFFSET " . $t . ' ') or die(mysql_error()); } } while ($row = mysql_fetch_array($query)) { $toemail = $row[$email]; } require_once 'header.php'; $isvalid = verify_email($toemail); if ($isvalid == false) { $toemail = ''; } if ($toemail){ $m = new MAIL; $m->From(stripslashes($fromemail), stripslashes($display)); $m->AddTo($toemail); // LINE 96 $m->Subject(stripslashes($subject)); $m->Html($fullemail); //$c = $m->Connect('mail.hostname.com', 25, 'username', 'password') or die(print_r($m->Result)); $m->Send() ? '' : 'Error.'; } else { $skipped=$skipped+1; } $bt = $bt + 1; $t = $t + 1; if ($t == $counter[0]) { $bt = $b; $complete = true; } } if ($counter[0] != $t) { header('Refresh: ' . $s . ';url=?t=' . $t.'&sk='.$skipped); } $value = (100 / $counter[0]); $value = $value * $t; $value = ceil($value); if ($complete) { echo '<div align="center"><h2>Complete!</h2>Sent ' . $t . ' emails.</div>'; } else { build_bar($value, $t, $counter[0], $s); } function build_bar($value, $t, $e, $s) { echo '<div align="center">'; echo '<table border="0" width="300"><tr><td align="left" width="200">'; $newval = $value * 2; if ($newval >= 200) { $newval = 200; } echo '<table border="0" width="200" bgcolor="gray"><tr><td width="' . $newval . '" bgcolor="navy">'; if ($value >= 1) { echo ' '; } echo '</td><td></td></tr></table>'; echo '</td><td align="center"><a href="?t=' . $t . '">Recover</a></td>'; echo '</td></tr></table>'; echo $value . '% Complete<br>' . $t . ' Emails Sent - ' . $e . ' Addresses Found<br>'.$_GET['sk'].' - Skipped'; echo '</div>'; } function verify_email($email){ if(!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/',$email)){ return false; } else { return $email; } } function ENCRYPT_DECRYPT($Str_Message) { $Len_Str_Message = STRLEN($Str_Message); $Str_Encrypted_Message = ""; for ($Position = 0; $Position < $Len_Str_Message; $Position++) { $Key_To_Use = (($Len_Str_Message + $Position) + 1); $Key_To_Use = (255 + $Key_To_Use) % 255; $Byte_To_Be_Encrypted = SUBSTR($Str_Message, $Position, 1); $Ascii_Num_Byte_To_Encrypt = ORD($Byte_To_Be_Encrypted); $Xored_Byte = $Ascii_Num_Byte_To_Encrypt ^ $Key_To_Use; $Encrypted_Byte = CHR($Xored_Byte); $Str_Encrypted_Message .= $Encrypted_Byte; } return $Str_Encrypted_Message; } ?> PHP: I've added comments where line 78 and 96 are. Any ideas guys? To make it skip the invalid emails instead of crashing?
I added comments in case you missed them: if ($wheres) { // LINE 78 and $m->AddTo($toemail); // LINE 96 I don't understand this at all. I can't do OO PHP...
As you said I think its an invalid email in the database, and the only way to make the script work is to make sure that the 'rouge' email is valid before sending it, which, it looks like it has already done, and this is far too complicated for me to work out, so good luck with it.
my registration page has got a pretty good regex to filter out invalid emails... it must be something simple. kinda impossible to go through all the emails if i dont know what im looking for
any other ideas? maybe there's an easy way to make it skip invalid emails to avoid crashing? php gurus?
Just print out each email address before sending it to the problem function. The last one that gets displayed will be the one that caused the error.
I don't want to send out another invalid email letter. I guess it could be changed to only go through the emails and skip the sending part. But not sure how to do that. Also, does anyone know how I can use a regex to pull emails using an SQL command? /^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/ I could pull them out manually.
<?php $string = "hello my email is something@hotmail.co.uk"; preg_match_all("/([a-z0-9\-_\.]*@[a-z0-9\-]*\.[a-z\.]{2,6})/i", $string, $matches); print_r($matches[0]); ?> PHP: Use preg_match_all to pull emails out, emails are in an array, which means you can pull them out manually...
Found the invalid email type: Doesn't seem like something that would cause an error. Could anyone improve this regex /^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/ to skip emails that have _ sign after the @ sign - that's what causes the error. _ in domain...
Or a simple regex that lets me pull emails from db that have _ signs after the @ sign would also help a lot!
For a start you have not escaped the - which is a special regex character for range, secondly your doing A-z - which is invalid if you want to match both do a-zA-Z or simply just do a-z and add the i modifier to the end. /^[_a-z0-9\-]+((\.|\+)[_a-z0-9\-]+)*@[a-z0-9\-]+(\.[a-z0-9\-]+)*(\.[a-z]{2,4})$/i
Lol @ this: Alternately [I dont understand regular expressions so :|] use this very large email regular expression checkerwhotzit. I think it'd work, but try: (?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t] )+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?: \r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:( ?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\0 31]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\ ](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+ (?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?: (?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z |(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n) ?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\ r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n) ?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t] )*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])* )(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t] )+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*) *:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+ |\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r \n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?: \r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t ]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031 ]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\]( ?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(? :(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(? :\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(? :(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)? [ \t]))*"(?:(?:\r\n)?[ \t])*)*:(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]| \\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<> @,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|" (?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t] )*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\ ".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(? :[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[ \]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000- \031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|( ?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,; :\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([ ^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\" .\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\ ]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\ [\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\ r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\] |\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \0 00-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\ .|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@, ;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(? :[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])* (?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\". \[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[ ^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\] ]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)(?:,\s*( ?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\ ".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:( ?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[ \["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t ])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t ])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(? :\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+| \Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?: [^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\ ]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n) ?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[" ()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n) ?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<> @,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@, ;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t] )*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\ ".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)? (?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\". \[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?: \r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[ "()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t]) *))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]) +|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\ .(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z |(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:( ?:\r\n)?[ \t])*))*)?;\s*) Code (markup): Random googling found that