Re: Mail sending program (beginner)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/10/06, aci india <foraci@xxxxxxxxx> wrote:
NOTE: Sorry for the very long code

Please paste long code snippets in a website like
pastebin.com. Also, the code is hard to read because
of the complete lack of indentation.

I suggest you atleast attempt to debug your code before
posting it here. Sprinkle echo or var_dump statements
throughout your code and try to find out where the problem
is. Make liberal use of the documentation at php.net/manual.

I have placed some comments inline, and pointed
out your infinite loop.

the mail.php file:

^^^^^^^^^^^^^^^

<?php

/*mail body file*/

function cnd($fname)

{

$fil = fopen($fname,"r");

if(!$fil)

die("fopen error");

while(!feof($fil))

$buffer = fgets($fil);

while($buffer != NULL)

{

if($buffer == "\n.") /*a line should not start with .*/

What is this? You are checking if the whole string is
equal to "\n.", which I think will never happen.

You probably want $buffer{0} == '.'/

$buffer = str_replace("\n.","\n..", $buffer);

As above.

if($buffer == "\n" && $buffer > 70) /*should be less than 70*/

What is this supposed to be? You are checking if
the line is empty, and then checking if it is greater
than 70? And you probably mean strlen in the second
part of the if.

$buffer = '\n';

}

fclose($fil);

return $buffer;

}

/*mail sub file*/

function sub($fname)

{

$fil = fopen($fname,"r");

if(!$fil)

die("fopen err in sub file");

while(!feof($fil))

$buff = fgets($fil);

while($buff != NULL)

{

if($buff > 15)

strlen here too. Strings don't magically give out their
length.

{

?>

<script language="javascript">

alert("the subject line should not be less than 15, pls check the sub.txtfile");

</script>
<?php

}

}

fclose($fil);

return $buff;

}

function fetch_names()

{

$var = mysql_connect("localhost","root","");

if(!$var)

die("could not connect".mysql_error());

$db = mysql_select_db("sathya_clon",$var);

if(!$db)

die("could not find the data base".mysql_error());

$result = mysql_query("select name from users",$var) or die("unable to fetch
rows");

$rows = mysql_fetch_array($result);

while($rows)

{

Here's your infinite loop. Review the docs on how to
iterate through returned rows. php.net/mysql_query.


for($i=0; $i<= $rows ; $i++)

for($j=0;$j <= i-1 ; $j++)

$names[$i] = $rows[$j];

}

return $names;

}

function fetch_emails()

{

$var = mysql_connect("localhost","root","");

if(!$var)

die("could not connect".mysql_error());

$db = mysql_select_db("sathya_clon",$var);

if(!$db)

die("could not find the data base".mysql_error());

$result = mysql_query("select email from users",$var) or die("unable to
fetch rows");

$rows = mysql_fetch_array($result);

while($rows)

{

One more infinite loop.


for($i=0; $i<= $rows ; $i++)

for($j=0;$j <= i-1 ; $j++)

$email[$i] = $rows[$j];

}

return $email;

}

$var = mysql_connect("localhost","root","");

if(!$var)

die("could not connect".mysql_error());

$db = mysql_select_db("sathya_clon",$var);

if(!$db)

die("could not find the data base".mysql_error());

$name = $_POST['user_name'];

$mail = $_POST['user_email'];

$db_q = mysql_query("insert into users values('$name','$mail')");

This is open to SQL injection attacts. See
php.net/mysql_real_escape_string and phpsec.org

if(!$db_q)

die("mysql error");

$condt = cnd("cond.txt");

$sub = sub ("sub.txt");

$name = fetch_names();

$email = fetch_emails();

$mail_stat = mail($email,$sub,$condt,"from:comp@xxxxxxxxxx");

if($mail_stat == NULL)

mail doesn't return NULL. php.net/mail.

echo "mail sent failed";

else

echo "mail sent sucess. Pls check for mail for further acction";

?>
==================code ends

Rabin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux