+ Reply to Thread
Results 1 to 4 of 4

Thread: foward mail to a php script

  1. #1
    ruicos is offline x10Hosting Member ruicos is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    9

    foward mail to a php script

    I have been trying to foward a mail to a php script. So I pipe my mail account to the php script. The problem is what should i put in the php script to process the email?

  2. #2
    phpasks is offline x10 Sophmore phpasks is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    145

    Re: foward mail to a php script

    You can send Mail no. of member.
    PHP Code:
    <?php
    $link 
    mysql_connect('mysql_host''mysql_user''mysql_password');
    mysql_select_db('mysql_dbname'$link); 

    $str_query =     "select * from tablename limit 0, 10";
    $recresult mysql_query($str_query$link);

    $i    =    0;
    $counter 1;
    while( 
    $obj_row mysql_fetch_array($recresultMYSQL_ASSOC) )
    {
        
    $to      $obj_row["to_mail"];
        
    $subject 'You can Subject Every Time';
        
    $message 'You can change Message Every Time';
        
        
    $headers 'From: webmaster@example.com' "\r\n" .
            
    'Reply-To: webmaster@example.com' "\r\n" .
            
    'X-Mailer: PHP/' phpversion();
        
        
    mail($to$subject$message$headers);
       
        
    sleep(2);
    }
    ?>
    Sleep need other wise your mail sent into user Junkbox.

    You can see this article
    http://www.phpasks.com/articles/fowa...phpscript.html
    Last edited by phpasks; 09-11-2008 at 11:50 PM. Reason: Link Add
    Asif Khalyani
    http://www.phpasks.com

  3. #3
    ruicos is offline x10Hosting Member ruicos is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    9

    Re: foward mail to a php script

    I am using the following code in test.php :
    Code:
    #!/usr/bin/php -q
    <?php
    $fd = fopen("php://stdin", "r");
    $email = "";
    while (!feof($fd)) {
    $email .= fread($fd, 1024);
    }
    fclose($fd);
    // handle email
    
    $lines = explode("\n", $email);
    
    // empty vars
    
    $from = "";
    $subject = "";
    $headers = "";
    $message = "";
    $splittingheaders = true;
    
    for ($i=0; $i < count($lines); $i++) {
    if ($splittingheaders) {
    // this is a header
    $headers .= $lines[$i]."\n";
    // look out for special headers
    if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
    $subject = $matches[1];
    }
    if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
    $from = $matches[1];
    }
    } else {
    // not a header, but message
    $message .= $lines[$i]."\n";
    }
    
    if (trim($lines[$i])=="") {
    // empty line, header section has ended
    $splittingheaders = false;
    }
    }
    
    ?>
    I pipe mail in cpanel to this script . However i am getting this error :


    This message was created automatically by mail delivery software.

    A message that you sent could not be delivered to one or more of its
    recipients. This is a permanent error. The following address(es) failed:

    pipe to |/home/ruicos/public_html/test.php
    generated by test@rcosta4540.x10hosting.com

    The following text was generated during the delivery attempt:

    ------ pipe to |/home/ruicos/public_html/test.php
    generated by test@rcosta4540.x10hosting.com ------


    ------ This is a copy of the message, including all the headers. ------
    I don't know what is wrong :S

  4. #4
    phpasks is offline x10 Sophmore phpasks is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    145

    Re: foward mail to a php script

    Your code is right.

    You can ask server administrator for mail script run or not.
    Asif Khalyani
    http://www.phpasks.com

+ Reply to Thread

Similar Threads

  1. Replies: 3
    Last Post: 03-10-2008, 12:22 PM
  2. PHP Versions & Resource Usage Script
    By Bryon in forum News and Announcements
    Replies: 11
    Last Post: 02-27-2008, 05:51 PM
  3. PHP Photo browser and x-fading slideshow script...
    By unmanaged in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 02-21-2008, 05:46 PM
  4. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  5. Problems with PHP Mail
    By Jarryd in forum Free Hosting
    Replies: 4
    Last Post: 11-26-2007, 09:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers