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'...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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. |
|
|||
|
"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" ); ?> |
|
|||
|
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. |
|
|||
|
"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? |
|
|||
|
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 |
|
|||
|
"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 |