PHP srnd two emails

This is a discussion on PHP srnd two emails within the PHP Language forums, part of the PHP Programming Forums category; Hi at all I call this function when I fill the foot of the body of the email that I'...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-27-2007
Pablo
 
Posts: n/a
Default PHP srnd two emails

Hi at all

I call this function when I fill the foot of the body of the email that I'll
send immediately after:

$text.=serial_number();

function serial_number()

{

$file="serial.txt";

for ($try = 0; $try < 5; $try++)

{

$fp = fopen($file, "a+");

if (flock($fp, LOCK_EX)) { // do an exclusive lock

fseek($fp, 0);

$id = fread($fp, 1024);

$id++;

ftruncate($fp, 0);

fwrite($fp, strval($id));

flock($fp, LOCK_UN); // release the lock

break;

}

else

{

sleep(1);

continue;

}

}

fclose($fp);

return $id;

}

The email is sended better and into the last line of the body there is the
new serial number

BUT......... IMMEDIATELY AFTER is sended a second EMPTY email without body
that contain only the serial number (new)

Please where wrong I?

Thank you very much in adbance

Pablo


Reply With Quote
  #2 (permalink)  
Old 06-28-2007
shimmyshack
 
Posts: n/a
Default Re: PHP srnd two emails

On Jun 27, 9:50 pm, "Pablo" <p...@nospam.com> wrote:
> Hi at all
>
> I call this function when I fill the foot of the body of the email that I'll
> send immediately after:
>
> $text.=serial_number();
>
> function serial_number()
>
> {
>
> $file="serial.txt";
>
> for ($try = 0; $try < 5; $try++)
>
> {
>
> $fp = fopen($file, "a+");
>
> if (flock($fp, LOCK_EX)) { // do an exclusive lock
>
> fseek($fp, 0);
>
> $id = fread($fp, 1024);
>
> $id++;
>
> ftruncate($fp, 0);
>
> fwrite($fp, strval($id));
>
> flock($fp, LOCK_UN); // release the lock
>
> break;
>
> }
>
> else
>
> {
>
> sleep(1);
>
> continue;
>
> }
> }
>
> fclose($fp);
>
> return $id;
>
> }
>
> The email is sended better and into the last line of the body there is the
> new serial number
>
> BUT......... IMMEDIATELY AFTER is sended a second EMPTY email without body
> that contain only the serial number (new)
>
> Please where wrong I?
>
> Thank you very much in adbance
>
> Pablo


try showing us the code that does the emailing, rather than the code
that tries 5 times to add a serial number to the end of a string.

Reply With Quote
  #3 (permalink)  
Old 06-28-2007
Pablo
 
Posts: n/a
Default Re: PHP srnd two emails


"shimmyshack"
wrote

>
> try showing us the code that does the emailing, rather than the code
> that tries 5 times to add a serial number to the end of a string.
>


<?PHP

function serialize()

{

$file="serial.txt";

for ($try = 0; $try < 5; $try++)

{

$fp = fopen($file, "a+");

if (flock($fp, LOCK_EX)) { // do an exclusive lock

fseek($fp, 0);

$id = fread($fp, 1024);

$id++;

ftruncate($fp, 0);

fwrite($fp, strval($id));

flock($fp, LOCK_UN); // release the lock

break;

}

else

{

sleep(1);

continue;

}

}

fclose($fp);

return $id;

}

$mail_text="Dear Sirs,\nthis is my question for you...........\n\r";

$mail_text.=$_REQUEST['body_of_question']."\n\n";

$mail_text.="Serial n.".serialize()."\n\n";

$mail_subject="Questions";

$mail_to=$_REQUEST['mailto'];

$mail_from=$_REQUEST['_mailfrom'];

$sended=@mail( $mail_to, $mail_subject, $mail_text, "From:
{$mail_from}\n" );

?>


Reply With Quote
  #4 (permalink)  
Old 06-28-2007
shimmyshack
 
Posts: n/a
Default Re: PHP srnd two emails

On Jun 28, 7:56 am, "Pablo" <p...@nospam.com> wrote:
> "shimmyshack"
> wrote
>
>
>
> > try showing us the code that does the emailing, rather than the code
> > that tries 5 times to add a serial number to the end of a string.

>
> <?PHP
>
> function serialize()
>
> {
>
> $file="serial.txt";
>
> for ($try = 0; $try < 5; $try++)
>
> {
>
> $fp = fopen($file, "a+");
>
> if (flock($fp, LOCK_EX)) { // do an exclusive lock
>
> fseek($fp, 0);
>
> $id = fread($fp, 1024);
>
> $id++;
>
> ftruncate($fp, 0);
>
> fwrite($fp, strval($id));
>
> flock($fp, LOCK_UN); // release the lock
>
> break;
>
> }
>
> else
>
> {
>
> sleep(1);
>
> continue;
>
> }
> }
>
> fclose($fp);
>
> return $id;
>
> }
>
> $mail_text="Dear Sirs,\nthis is my question for you...........\n\r";
>
> $mail_text.=$_REQUEST['body_of_question']."\n\n";
>
> $mail_text.="Serial n.".serialize()."\n\n";
>
> $mail_subject="Questions";
>
> $mail_to=$_REQUEST['mailto'];
>
> $mail_from=$_REQUEST['_mailfrom'];
>
> $sended=@mail( $mail_to, $mail_subject, $mail_text, "From:
> {$mail_from}\n" );
>
> ?>


from that I can't see why, however you are encouraged to use PhpMailer
or some other email class tp send your mail. At least that way will
know that the implementation is ok, the way you are currently using
the mail() call could lead to problems as you dont appear to be
santitising the input.

Reply With Quote
  #5 (permalink)  
Old 06-28-2007
Pablo
 
Posts: n/a
Default Re: PHP srnd two emails


"shimmyshack"
wrote


>
> from that I can't see why, however you are encouraged to use PhpMailer
> or some other email class tp send your mail. At least that way will
> know that the implementation is ok, the way you are currently using
> the mail() call could lead to problems as you dont appear to be
> santitising the input.
>


Have you some other best way please?


Reply With Quote
  #6 (permalink)  
Old 06-28-2007
shimmyshack
 
Posts: n/a
Default Re: PHP srnd two emails

On Jun 28, 2:34 pm, "Pablo" <p...@nospam.com> wrote:
> "shimmyshack"
> wrote
>
>
>
> > from that I can't see why, however you are encouraged to use PhpMailer
> > or some other email class tp send your mail. At least that way will
> > know that the implementation is ok, the way you are currently using
> > the mail() call could lead to problems as you dont appear to be
> > santitising the input.

>
> Have you some other best way please?


write slightly better code would be my only other way

Reply With Quote
  #7 (permalink)  
Old 06-28-2007
Pablo
 
Posts: n/a
Default Re: PHP srnd two emails

"shimmyshack"

wrote

>however you are encouraged to use PhpMailer
> or some other email class tp send your mail.


Please how can I understand if the PHP version that work into my web site
support PHPMailer?

And if it do not support PHPMailer what can I do?

Thank you


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:32 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0