This is a discussion on Send mail using external server within the PHP General forums, part of the PHP Programming Forums category; Hi there! I'm developing a program that has a kind of mail client from where users can send mails ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi there!
I'm developing a program that has a kind of mail client from where users can send mails and get a blind copy in their e-mail boxes. The program uses mail() in those servers having a SMTP installed in the very same server. I would like to let people send mails even if the server is not able to handle them. To do that I've googled around and found the following script (see below). The problem is that blind copies don't reach destination, mails in the To: field arrive well, mails in the BCC: desappear and never reach the mailbox (nor get back :-? Does anyone know what's going wrong? Thanks. <? /* pipemail v.0.1 PHP-script to send mails via socket, e.g. using an external smtp-server (c) Robert Strouhal 2002 http://www.strouhal.de Feel free to use, copy and modify this script. PLEASE REMIND: IT COMES WITH ABSOLUTELY NO GUARANTEE! How to use: ------- Integrate the file to your own sripts by using "require" or "inlude" Modify the setting in line 30-32 gosmtp($from,$to,$subject,$cc,$bcc,$message); Example: gostmtp("sender@host.de", "recipient@host.de", "This is my subject", "","", "This is my message to you"); */ // settings, please modify for your own website global $server, $port, $logsmtp; $server = "$mailServer"; //domain of your smtp-server $port = 25; //SMTP-Port, usually 25 $logsmtp = 1; //set 1 if the smtp communication should be logged to the file smtp.log in the same folder // don't edit the code below as long as you don't know what to do... function listen2server() { global $log; global $server; global $socket; global $logsmtp; $antwort = fgets($socket, 1500); if ($logsmtp=='1') { $log = "SERVER: ".$antwort; $datei = fopen("smtp.log", "a"); fputs($datei, "$log"); fclose($datei); } $code = substr($antwort, 0, 3); return $code; } function talk2server($commands) { global $log; global $server; global $socket; global $logsmtp; fputs($socket,$commands); if ($logsmtp=='1') { $log = "CLIENT: ".$commands; $datei = fopen("smtp.log", "a"); fputs($datei, "$log"); fclose($datei); } } function gosmtp($from,$to,$subject,$cc,$bcc,$message) { global $server; global $socket; global $port; global $logsmtp; if ($socket = fsockopen($server,$port)) { //set_socket_timeout($socket, 30); if (listen2server() == "220") talk2server("HELO ".getenv('HTTP_HOST')."\n"); if (listen2server() == "250") talk2server("MAIL FROM: ".$from."\n"); if (listen2server() == "250") talk2server("RCPT TO: ".$to."\n"); if (listen2server() == "250") talk2server("DATA\n"); if (listen2server() == "354") { $content = "Subject: $subject\r\n"; $content .= "From: $from\r\n"; $content .= "To: $to\r\n"; if ($cc!="") { $content .= "Cc: $cc\r\n"; } if ($bcc!="") { $content .= "Bcc: $bcc\r\n"; } $content .= "Reply-To: $from\r\n"; $content .= "Errors-To: $from\r\n"; $content .= "Bounce-To: $from\r\n"; $content .= "X-Mailer: sent via PipeMail v0.1, check www.strouhal.de for the PHP script\r\n"; $content .= "X-Please_remind: I am not responsible for the misuse (spam...) of this script!\r\n"; $content .= "\r\n".$message."\r\n"; $content .= ".\r\n"; echo "<PRE>$content</PRE>"; talk2server($content); if (listen2server() == "250") {//listen2server(); $mailsent = true;} else {$mailsent = false; //listen2server(); } } talk2server("QUIT\n"); listen2server(); if ($mailsent) { echo "<P>Mail sent</P>"; return true; } else { echo "<tt><font color='red'>Couldn't deliver mail to $to!</b></font></tt><br>\n"; return false; } } else { echo "<tt><font color='red'>Wasn't able to connect to $server:$port!</b></font></tt><br>"; return false; } } ?> __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com |
|
|||
|
http://phpmailer.sourceforge.net/
This is what I use and makes life much much easier Pete Maria Garcia Suarez wrote: > Hi there! > > I'm developing a program that has a kind of mail > client from where users can send mails and get a blind > copy in their e-mail boxes. The program uses mail() in > those servers having a SMTP installed in the very same > server. I would like to let people send mails even if > the server is not able to handle them. > > To do that I've googled around and found the following > script (see below). The problem is that blind copies > don't reach destination, mails in the To: field arrive > well, mails in the BCC: desappear and never reach the > mailbox (nor get back :-? > > Does anyone know what's going wrong? Thanks. > > <? > /* > pipemail v.0.1 > > PHP-script to send mails via socket, e.g. using > an external smtp-server > > (c) Robert Strouhal 2002 > http://www.strouhal.de > > Feel free to use, copy and modify this script. > PLEASE REMIND: IT COMES WITH ABSOLUTELY NO GUARANTEE! > > How to use: > ------- > Integrate the file to your own sripts by using > "require" or "inlude" > Modify the setting in line 30-32 > gosmtp($from,$to,$subject,$cc,$bcc,$message); > Example: gostmtp("sender@host.de", > "recipient@host.de", > "This is my subject", "","", "This is my message to > you"); > */ > > > // settings, please modify for your own website > global $server, $port, $logsmtp; > $server = "$mailServer"; //domain of your > smtp-server > $port = 25; //SMTP-Port, usually 25 > $logsmtp = 1; //set 1 if the smtp > communication should be logged to the file smtp.log in > the same folder > > // don't edit the code below as long as you don't know > what to do... > > function listen2server() { > > global $log; > global $server; > global $socket; > global $logsmtp; > > $antwort = fgets($socket, 1500); > > if ($logsmtp=='1') { > $log = "SERVER: ".$antwort; > $datei = fopen("smtp.log", "a"); > fputs($datei, "$log"); > fclose($datei); > } > > $code = substr($antwort, 0, 3); > return $code; > > } > > > function talk2server($commands) { > > global $log; > global $server; > global $socket; > global $logsmtp; > > fputs($socket,$commands); > > if ($logsmtp=='1') { > $log = "CLIENT: ".$commands; > $datei = fopen("smtp.log", "a"); > fputs($datei, "$log"); > fclose($datei); > } > } > > > function gosmtp($from,$to,$subject,$cc,$bcc,$message) > { > > global $server; > global $socket; > global $port; > global $logsmtp; > > if ($socket = fsockopen($server,$port)) > { > //set_socket_timeout($socket, 30); > if (listen2server() == "220") > talk2server("HELO ".getenv('HTTP_HOST')."\n"); > if (listen2server() == "250") > talk2server("MAIL FROM: ".$from."\n"); > if (listen2server() == "250") > talk2server("RCPT TO: ".$to."\n"); > if (listen2server() == "250") > talk2server("DATA\n"); > if (listen2server() == "354") > { > $content = "Subject: $subject\r\n"; > $content .= "From: $from\r\n"; > $content .= "To: $to\r\n"; > if ($cc!="") { > $content .= "Cc: $cc\r\n"; > } > if ($bcc!="") { > $content .= "Bcc: $bcc\r\n"; > } > $content .= "Reply-To: $from\r\n"; > $content .= "Errors-To: > $from\r\n"; > $content .= "Bounce-To: > $from\r\n"; > $content .= "X-Mailer: sent via > PipeMail v0.1, check www.strouhal.de for the PHP > script\r\n"; > $content .= "X-Please_remind: I am > not responsible for the misuse (spam...) of this > script!\r\n"; > $content .= > "\r\n".$message."\r\n"; > $content .= ".\r\n"; > echo "<PRE>$content</PRE>"; > talk2server($content); > if (listen2server() == "250") > {//listen2server(); > $mailsent = true;} > else > {$mailsent = false; > //listen2server(); > } > > } > talk2server("QUIT\n"); > listen2server(); > > if ($mailsent) { > echo "<P>Mail sent</P>"; > return true; > } else { > echo "<tt><font color='red'>Couldn't deliver > mail to $to!</b></font></tt><br>\n"; > return false; > } > } > > else > { > echo "<tt><font color='red'>Wasn't able to connect to > $server:$port!</b></font></tt><br>"; > return false; > } > } > > ?> > > __________________________________ > Do you Yahoo!? > SBC Yahoo! DSL - Now only $29.95 per month! > http://sbc.yahoo.com |
|
|||
|
Maria Garcia Suarez <mariagarciasuarez@yahoo.com> wrote:
> > [...] > > > talk2server("MAIL FROM: ".$from."\n"); > > > if (listen2server() == "250") > > > talk2server("RCPT TO: ".$to."\n"); You must send the rctp to's bfore you start sending the data. To be a more stable smtp client there should be more sanity checking before blindy doing this: if ($cc != "") { $CC = split(',', $cc); foreach ($CC as $ccemal) { talk2server("RCPT TO: $ccemail\n"); } } Then repeat for BCC's > > > if (listen2server() == "250") > > > talk2server("DATA\n"); > > > if (listen2server() == "354") > > > { > > > $content = "Subject: $subject\r\n"; > > > $content .= "From: $from\r\n"; > > > $content .= "To: $to\r\n"; > > > if ($cc!="") { > > > $content .= "Cc: $cc\r\n"; > > > } > > > if ($bcc!="") { > > > $content .= "Bcc: $bcc\r\n"; > > > } Be sure to remove the bcc header, it wont be very blind if the recipients can see who was blind carbon copied. > > the problem is that the script should send a "RCPT > > TO" for every recipient, > > and it only send it for $to > > so this script only works with the $to field, > > neither the $cc nor $bcc will > > work... > > moreover, the "$content .= "Bcc: $bcc\r\n";" line > > should not go!!! > > if not you are putting the info about the BCC in the > > mail headers and > > everyone will be able to see it.. > > What should I change in the script in order to make it > work? > > Thanks a lot for your help. > > Besos, > Maria > Curt -- |
|
|||
|
Hello,
On 07/14/2003 11:27 AM, Maria Garcia Suarez wrote: > Hi there! > > I'm developing a program that has a kind of mail > client from where users can send mails and get a blind > copy in their e-mail boxes. The program uses mail() in > those servers having a SMTP installed in the very same > server. I would like to let people send mails even if > the server is not able to handle them. > > To do that I've googled around and found the following > script (see below). The problem is that blind copies > don't reach destination, mails in the To: field arrive > well, mails in the BCC: desappear and never reach the > mailbox (nor get back :-? > > Does anyone know what's going wrong? Thanks. That script has lots of problems from wrong line endings to the inability to handle multiline SMTP responses. You may want to use this SMTP class instead: http://www.phpclasses.org/smtpclass Actually, if you want to use a direct replacement for the mail() function you may want to try this other class in conjunction as it comes with a wrapper function named smtp_mail() that emulates the mail() function but lets you send it via SMTP directly. http://www.phpclasses.org/mimemessage -- Regards, Manuel Lemos Free ready to use OOP components written in PHP http://www.phpclasses.org/ |
|
|||
|
Hi there!
--- Juan Nin <juaid@juanin.com> wrote: > From: "Curt Zirzow" <curt@zirzow.dyndns.org> > > You must send the rctp to's bfore you start > sending the data. To be > > a more stable smtp client there should be more > sanity checking before > > blindy doing this: > > > > if ($cc != "") { > > $CC = split(',', $cc); > > foreach ($CC as $ccemal) { > > talk2server("RCPT TO: $ccemail\n"); > > } > > } > > Then repeat for BCC's > good!! you also included the code for her :) With the proposed changes does it become something usable? I wouldn't like to start using a "huge" (somehow, compared to this little script) script just to send a very simple mail... Thanks! Kisses, Maria __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com |
|
|||
|
From: "Maria Garcia Suarez" <mariagarciasuarez@yahoo.com>
> The problem is that blind copies > don't reach destination, mails in the To: field arrive > well, mails in the BCC: desappear and never reach the > mailbox (nor get back :-? [...] > talk2server("MAIL FROM: ".$from."\n"); > if (listen2server() == "250") > talk2server("RCPT TO: ".$to."\n"); > if (listen2server() == "250") > talk2server("DATA\n"); > if (listen2server() == "354") > { > $content = "Subject: $subject\r\n"; > $content .= "From: $from\r\n"; > $content .= "To: $to\r\n"; > if ($cc!="") { > $content .= "Cc: $cc\r\n"; > } > if ($bcc!="") { > $content .= "Bcc: $bcc\r\n"; > } the problem is that the script should send a "RCPT TO" for every recipient, and it only send it for $to so this script only works with the $to field, neither the $cc nor $bcc will work... moreover, the "$content .= "Bcc: $bcc\r\n";" line should not go!!! if not you are putting the info about the BCC in the mail headers and everyone will be able to see it.. regards, Juan |
|
|||
|
From: "Curt Zirzow" <curt@zirzow.dyndns.org>
> You must send the rctp to's bfore you start sending the data. To be > a more stable smtp client there should be more sanity checking before > blindy doing this: > > if ($cc != "") { > $CC = split(',', $cc); > foreach ($CC as $ccemal) { > talk2server("RCPT TO: $ccemail\n"); > } > } > > Then repeat for BCC's good!! you also included the code for her :) > Be sure to remove the bcc header, it wont be very blind if the > recipients can see who was blind carbon copied. I'm really surprised at this script... I can't believe someone posted that script for being downloaded while it has several things that are completely wrong!!! Specially the including the BCC in the header's in a way that anyone can see it!!! obviously this programmer did not have many clues on how SMTP works, and didn't waste many of his time investigating it... it really surprises me.. Juan |
|
|||
|
From: "Maria Garcia Suarez" <mariagarciasuarez@yahoo.com>
> With the proposed changes does it become something usable? it all depends on what you mean by "usable"!!! :oP if it works for what you want, and it satisfies your needs, then you can use it test it, and if it works ok for you, and don't want to use another one, well just do it :) regards, Juan |