j5uh Posted May 30, 2008 Share Posted May 30, 2008 Please help! ??? I'm in need of a software or php script that can forward an email to a list that is on a mysql db. So an email will be sent to a specific email address and that should trigger the software or script to run through the email addresses in the db and forward that to everyone. Any ideas? Quote Link to comment Share on other sites More sharing options...
rubing Posted May 30, 2008 Share Posted May 30, 2008 Yeah, i would just set up a forwarder. So, that when this address is emailed its sent to a php script that retrieves your mailing list and mails everybody. Are you using cpanel? Quote Link to comment Share on other sites More sharing options...
j5uh Posted May 30, 2008 Author Share Posted May 30, 2008 I'm actually using godaddy hosting. Do you have a script in mind that I can use? not sure how i can tie in an address with a script. Quote Link to comment Share on other sites More sharing options...
j5uh Posted May 30, 2008 Author Share Posted May 30, 2008 could you explain the cPanel way too? I guess I could use one of my other hosting companies to see how it would work... but if I can get it working on godaddy, it would be ideal. Quote Link to comment Share on other sites More sharing options...
j5uh Posted May 30, 2008 Author Share Posted May 30, 2008 ok with cpanel, i'm guessing you just use the pipe method to pipe the email into a script. interesting. Quote Link to comment Share on other sites More sharing options...
rubing Posted May 31, 2008 Share Posted May 31, 2008 Yeah that's exactly what I was reccomending! Do you want me to explain how to set it up in cpanel? If you're using GoDady we should figure something else out. Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 2, 2008 Author Share Posted June 2, 2008 ok sweet! i've switched providers to hostgator and i have cpanel running. Does anyone have a script by any chance that can forward the email address to the correct mail list from a db? Here is the script I'm using so far and it's not working... <?php include("config.php"); mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); $sql = "SELECT $db_emailfield FROM $db_table"; $result = mysql_query($sql); $email_file = fopen("php://stdin", "r"); while($row = mysql_fetch_array($result)){ $email = $row['email']; $message = $email_file; $mailhead = 'MIME-Version: 1.0' . "\n"; $mailhead .= 'Content-type: text/html; charset=UTF-8' . "\n"; $mailhead .= "From: $fromname\n"; if(mail ($email, $emailsubject, $message, "From: $fromname <$fromemail>", $mailhead)) echo "Messages sent"; } ?> Quote Link to comment Share on other sites More sharing options...
rubing Posted June 3, 2008 Share Posted June 3, 2008 In cpanel configure your email forwarder to pipe received email to a php script like this: email@youraddress.com |/home/name/path/to/script.php Now, make your php script executable by including the hash bang symbol (#!) and the path to your php installation on the top line before the opening php tag. Also set error reporting to all. Now, when you email this address, any errors will bounce back to your email client. Let us know the errors you get. #!/usr/bin/php -q <?php ini_set('error_reporting',E_ALL); Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 3, 2008 Author Share Posted June 3, 2008 ok here is what i have now... #!/usr/bin/php -q <?php ini_set('error_reporting',E_ALL); include("config.php"); mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); $sql = "SELECT $db_emailfield FROM $db_table"; $result = mysql_query($sql); $email_file = fopen("php://stdin", "r"); while($row = mysql_fetch_array($result)){ $email = $row['email']; $message = $email_file; $mailhead = 'MIME-Version: 1.0' . "\n"; $mailhead .= 'Content-type: text/html; charset=UTF-8' . "\n"; $mailhead .= "From: $fromname\n"; if(mail ($email, $emailsubject, $message, "From: $fromname <$fromemail>", $mailhead)) echo "Messages sent"; } ?> The piping is correct ... I have /home/newhost/public_html/asd/ss/emailer.php When I access the script directly, it's giving me a an error below Warning: mail() expects parameter 3 to be string, resource given in /home/newhost/public_html/asd/ss/emailer.php on line 23 Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 3, 2008 Author Share Posted June 3, 2008 I've found this new script from here <? // Set some vars $ChangeTo = "changeto@domain.com"; $ForwardTo = "forwardto@domain.com"; // Read the pipe $open_file = fopen("php://stdin","r"); $email = ""; while (!feof($open_file)) { $email .= fread($open_file,1024); } fclose ($open_file); // Take info from emai; $lines = explode("\n",$email); $from = ""; $subject = ""; $message = ""; $to = $ChangeTo; $splittingheaders = true; for ($i=0;$i<count($lines);$i++) { if ($splittingheaders) { if (preg_match("/^From: (.*)/",$lines[$i],$matches)) { if (strpos($lines[$i],"<")) { // The name is before the email $data = explode ("<",$lines[$i]); $from = substr(trim($data[1]),0,-1); } else { $from = $matches[1]; } } if (preg_match("/^Subject: (.*)/",$lines[$i],$matches)) { $subject = $matches[1]; } } else { $message .= $lines[$i]."\n"; } if (trim($lines[$i]=="")) { $splittingheaders = false; } } $message = <<< EOF $message EOF; $headers = "Content-type: text/html\n"; $headers .= "From: $from\n"; $headers .= "Return-Path: $from\n"; //$headers .= "To: $to\n"; mail ($ForwardTo,$subject,$message,$headers); ?> It's exactly what I need but I need it to pull the list of emails from a DB... how can I modify this to that? Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 Not tested, but something like this: <?php ini_set('error_reporting',E_ALL); include("config.php"); mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); $sql = "SELECT $db_emailfield FROM $db_table"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ $email = $row['email']; $ChangeTo = $email; $ForwardTo = "forwardto@domain.com"; // Read the pipe $open_file = fopen("php://stdin","r"); $email = ""; while (!feof($open_file)) { $email .= fread($open_file,1024); } fclose ($open_file); // Take info from emai; $lines = explode("\n",$email); $from = ""; $subject = ""; $message = ""; $to = $ChangeTo; $splittingheaders = true; for ($i=0;$i<count($lines);$i++) { if ($splittingheaders) { if (preg_match("/^From: (.*)/",$lines[$i],$matches)) { if (strpos($lines[$i],"<")) { // The name is before the email $data = explode ("<",$lines[$i]); $from = substr(trim($data[1]),0,-1); } else { $from = $matches[1]; } } if (preg_match("/^Subject: (.*)/",$lines[$i],$matches)) { $subject = $matches[1]; } } else { $message .= $lines[$i]."\n"; } if (trim($lines[$i]=="")) { $splittingheaders = false; } } $message = <<< EOF $message EOF; $headers = "Content-type: text/html\n"; $headers .= "From: $from\n"; $headers .= "Return-Path: $from\n"; //$headers .= "To: $to\n"; mail ($ForwardTo,$subject,$message,$headers); } ?> Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 3, 2008 Author Share Posted June 3, 2008 jonsjava, I've ran that code but it's giving an error at Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/newhost/public_html/asd/ss/mailer.php on line 11 Which is the code while($row = mysql_fetch_array($result)){ I'm having trouble with that line of code. I can't seem to figure it out. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 that part was taken straight from your script. I left the variables in, because I don't know your variables. Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 3, 2008 Author Share Posted June 3, 2008 jonsjava, This is what I have #!/usr/bin/php -q <?php ini_set('error_reporting',E_ALL); $db_host = "asd"; $db_user = "asd"; $db_pwd = "asd"; $db_name = "asd"; $db_table = "asd"; $db_emailfield = "emails"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); $sql = "SELECT $db_emailfield FROM $db_table"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ $email = $row['email']; $ChangeTo = "noreply@asd.com"; $ForwardTo = $email; // Read the pipe $open_file = fopen("php://stdin","r"); $email = ""; while (!feof($open_file)) { $email .= fread($open_file,1024); } fclose ($open_file); // Take info from emai; $lines = explode("\n",$email); $from = ""; $subject = ""; $message = ""; $to = $ChangeTo; $splittingheaders = true; for ($i=0;$i<count($lines);$i++) { if ($splittingheaders) { if (preg_match("/^From: (.*)/",$lines[$i],$matches)) { if (strpos($lines[$i],"<")) { // The name is before the email $data = explode ("<",$lines[$i]); $from = substr(trim($data[1]),0,-1); } else { $from = $matches[1]; } } if (preg_match("/^Subject: (.*)/",$lines[$i],$matches)) { $subject = $matches[1]; } } else { $message .= $lines[$i]."\n"; } if (trim($lines[$i]=="")) { $splittingheaders = false; } } $message = <<< EOF $message EOF; $headers = "Content-type: text/html\n"; $headers .= "From: $from\n"; $headers .= "Return-Path: $from\n"; //$headers .= "To: $to\n"; mail ($ForwardTo,$subject,$message,$headers); } ?> Still giving me that line 11 error... =/ Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 #!/usr/bin/php -q <?php ini_set('error_reporting',E_ALL); $db_host = "asd"; $db_user = "asd"; $db_pwd = "asd"; $db_name = "asd"; $db_table = "asd"; $db_emailfield = "emails"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); $sql = "SELECT `$db_emailfield` FROM `$db_table`;"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ $email = $row['email']; $ChangeTo = "noreply@financial-robotics.com"; $ForwardTo = $email; // Read the pipe $open_file = fopen("php://stdin","r"); $email = ""; while (!feof($open_file)) { $email .= fread($open_file,1024); } fclose ($open_file); // Take info from emai; $lines = explode("\n",$email); $from = ""; $subject = ""; $message = ""; $to = $ChangeTo; $splittingheaders = true; for ($i=0;$i<count($lines);$i++) { if ($splittingheaders) { if (preg_match("/^From: (.*)/",$lines[$i],$matches)) { if (strpos($lines[$i],"<")) { // The name is before the email $data = explode ("<",$lines[$i]); $from = substr(trim($data[1]),0,-1); } else { $from = $matches[1]; } } if (preg_match("/^Subject: (.*)/",$lines[$i],$matches)) { $subject = $matches[1]; } } else { $message .= $lines[$i]."\n"; } if (trim($lines[$i]=="")) { $splittingheaders = false; } } $message = <<< EOF $message EOF; $headers = "Content-type: text/html\n"; $headers .= "From: $from\n"; $headers .= "Return-Path: $from\n"; //$headers .= "To: $to\n"; mail ($ForwardTo,$subject,$message,$headers); } ?> Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 3, 2008 Author Share Posted June 3, 2008 jonsjava, it's still giving me an error on this line while($row = mysql_fetch_assoc($result)){ I'm forever thankful for all your help... Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 lets try this: #!/usr/bin/php -q <?php ini_set('error_reporting',E_ALL); $db_host = "asd"; $db_user = "asd"; $db_pwd = "asd"; $db_name = "asd"; $db_table = "asd"; $db_emailfield = "emails"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); $sql = "SELECT `$db_emailfield` FROM `$db_table`;"; print $sql."\n"; //let me know all the output you receive, including your sql $result = mysql_query($sql); $array1 = array(); while($row = mysql_fetch_assoc($result)){ $array1[] .=$row['email']; } print_r($array1); ?> Lets see if it populates any data (making sure your query is working) Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 3, 2008 Author Share Posted June 3, 2008 i think it's working now !!!! =) let me check and report back to you... Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 I noticed that you have this: $db_emailfield = "emails"; yet, you set $email like this: $array1[] .=$row['email']; Which one is your field name? emails, or email? Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 3, 2008 Author Share Posted June 3, 2008 this is what i used and it's working!!! #!/usr/bin/php -q <?php ini_set('error_reporting',E_ALL); $db_host = "asd"; $db_user = "asd"; $db_pwd = "asd"; $db_name = "asd"; $db_table = "users"; $db_emailfield = "email"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); $sql = "SELECT `$db_emailfield` FROM `$db_table`;"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ $emails = $row['email']; $ChangeTo = "noreply@asd.com"; $ForwardTo = $emails; // Read the pipe $open_file = fopen("php://stdin","r"); $email = ""; while (!feof($open_file)) { $email .= fread($open_file,1024); } fclose ($open_file); // Take info from emai; $lines = explode("\n",$email); $from = ""; $subject = ""; $message = ""; $to = $ChangeTo; $splittingheaders = true; for ($i=0;$i<count($lines);$i++) { if ($splittingheaders) { if (preg_match("/^From: (.*)/",$lines[$i],$matches)) { if (strpos($lines[$i],"<")) { // The name is before the email $data = explode ("<",$lines[$i]); $from = substr(trim($data[1]),0,-1); } else { $from = $matches[1]; } } if (preg_match("/^Subject: (.*)/",$lines[$i],$matches)) { $subject = $matches[1]; } } else { $message .= $lines[$i]."\n"; } if (trim($lines[$i]=="")) { $splittingheaders = false; } } $message = <<< EOF $message EOF; $headers = "Content-type: text/html\n"; $headers .= "From: $from\n"; $headers .= "Return-Path: $from\n"; //$headers .= "To: $to\n"; mail ($ForwardTo,$subject,$message,$headers); } ?> Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 3, 2008 Author Share Posted June 3, 2008 ok... the script runs when i view it through my browser but no luck when i pipe the email to it.... I'm using /home/newhost/public_html/asd/ss/mailer.php any ideas? Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 3, 2008 Author Share Posted June 3, 2008 ok it's working now. had the email piping mixed up. my only concern is the emails are being sent but they go to junk and they send 2 copies of the same email. ??? Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 they will go to junk, usually, unfortunately. Darn spammers have given php mail a bad name...*sigh* Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 3, 2008 Author Share Posted June 3, 2008 I know the script is working but when I recieve the emails, I see no content or a From... what could be wrong? Quote Link to comment Share on other sites More sharing options...
rubing Posted June 3, 2008 Share Posted June 3, 2008 whatever you're trying to parse is probably not correct just in case try sending some plain text, to make sure the mailer works. You can use the mail extensions in PEAR, I don't think they will go to junk. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.