473,378 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

POP before SMTP

Hi all,

a friend using Windows wanted to send mail, but he got timeout errors
after editing php.ini Mail section

smtp = smtp.server.com
sendmail_from = fr****@server.com

I realized that was because of the need to "POP before SMTP",
so I made him a function. It's working ... for his server (and
hopefully other servers too).

Can this function be improved?
Is it ok to fsockopen in blocking mode?
What about timeout values?

Any hints to make this a more reliable function will be greatly
appreciated.
Here it is, hope it suits more Windows people without a mail server
and the need to POP before SMTP
<?php
function POP_authenticate($username, $password, $server) {
$socket = fsockopen($server, 110); // POP3 port
if (!$socket) {
return "Couldn't connect to $server:110\r\n";
}

$res = fgets($socket, 512); // read +OK
if (substr(trim($res), 0, 3) != "+OK") {
return $res; // return the error
}
fputs($socket, "USER $username\r\n"); // send user
$res = fgets($socket, 512); // read +OK
if (substr(trim($res), 0, 3) != "+OK") {
return $res;
}
fputs($socket, "PASS $password\r\n"); // send pass
$res = fgets($socket, 512); // read +OK
if (substr(trim($res), 0, 3) != "+OK") {
return $res;
}
fputs($socket, "QUIT\r\n"); // quit

### I don't care for errors after quitting :-)

fclose($socket);
return false;
}
?>

and this is an example on how you can use it:

<?php
$username = "netuser";
$password = "pAzw04D";
$POPserver = "pop.server.com";
### php.ini's SMTP must correspond to this server
### and sendmail_from must be from this server (??)

$msg = POP_authenticate($username, $password, $POPserver);
if ($msg === FALSE) {
mail("so*****@somewhere.com", "PHP test", "Line 1\nLine 2");
$msg = "mail (probably) sent.\r\n";
}
exit($msg);
?>
Comments? Suggestions? Corrections?
All are very welcome.

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #1
1 7469
I think your function is pretty well done.
"Pedro" <he****@hotpop.com> wrote in message
news:ie********************************@4ax.com...
Hi all,

a friend using Windows wanted to send mail, but he got timeout errors
after editing php.ini Mail section

smtp = smtp.server.com
sendmail_from = fr****@server.com

I realized that was because of the need to "POP before SMTP",
so I made him a function. It's working ... for his server (and
hopefully other servers too).

Can this function be improved?
Is it ok to fsockopen in blocking mode?
What about timeout values?

Any hints to make this a more reliable function will be greatly
appreciated.
Here it is, hope it suits more Windows people without a mail server
and the need to POP before SMTP
<?php
function POP_authenticate($username, $password, $server) {
$socket = fsockopen($server, 110); // POP3 port
if (!$socket) {
return "Couldn't connect to $server:110\r\n";
}

$res = fgets($socket, 512); // read +OK
if (substr(trim($res), 0, 3) != "+OK") {
return $res; // return the error
}
fputs($socket, "USER $username\r\n"); // send user
$res = fgets($socket, 512); // read +OK
if (substr(trim($res), 0, 3) != "+OK") {
return $res;
}
fputs($socket, "PASS $password\r\n"); // send pass
$res = fgets($socket, 512); // read +OK
if (substr(trim($res), 0, 3) != "+OK") {
return $res;
}
fputs($socket, "QUIT\r\n"); // quit

### I don't care for errors after quitting :-)

fclose($socket);
return false;
}
?>

and this is an example on how you can use it:

<?php
$username = "netuser";
$password = "pAzw04D";
$POPserver = "pop.server.com";
### php.ini's SMTP must correspond to this server
### and sendmail_from must be from this server (??)

$msg = POP_authenticate($username, $password, $POPserver);
if ($msg === FALSE) {
mail("so*****@somewhere.com", "PHP test", "Line 1\nLine 2");
$msg = "mail (probably) sent.\r\n";
}
exit($msg);
?>
Comments? Suggestions? Corrections?
All are very welcome.

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dan Boyle | last post by:
Hi, I am having difficulty connection to an smtp host. I am using the following code but I don't think I fully understand what smtp host can be used. function setSMTPParams($host = null,...
21
by: Nancy | last post by:
Hi, Guys, Is there any other way to use python or mod_python writing a web page? I mean, not use "form.py/email", no SMTP server. <form action="form.py/email" method="POST"> ... Thanks a lot. ...
0
by: Almir | last post by:
I hate this Net::SMTP stuff, everything works fine but for the suject field. I see no way of having it show in an email when sent. Has anyone had this problem, can anyone explain why there are no...
2
by: RandRace | last post by:
I'm having some problems with a little script i wrote using net::smtp. I originally wrote it in linux where it works perfectly. I tried to use it from windows the other day and it doesn't work. It...
3
by: Shannon Clyde | last post by:
SMTP + relay + auth in an IPSEC tunnel to connect to our primary SMTP mail server (GroupWise) from the Web server looks like it would work fine, but is it the best way? I am aware of CDOSYS and...
3
by: dale zhang | last post by:
Hi, I write an asp.net web application. It has a “Contact Us” page, where users fill in their email, subject and text and hit send. Then the email will go to my hard coded yahoo email...
1
by: bivin | last post by:
hai i am requesting your technical support. please help me. i have been working with this for five days. the problem is relating with the smtp. i am trying to send an email from the asp.net...
34
by: antonyliu2002 | last post by:
I've set up the virtual smtp server on my IIS 5.1 like so: 1. Assign IP address to "All Unassigned", and listen to port 25. 2. Access Connection granted to "127.0.0.1". 3. Relay only allow...
13
by: jcor | last post by:
Hi, I'm trying some code to send a mail with my script. This is it: #!/usr/bin/perl use Net::SMTP; my $smtp_server='62.193.245.15'; my $smtp = Net::SMTP->new($smtp_server) or die "Can't Open...
5
by: jimhill10 | last post by:
I have a perl script that creates an email attachment file from POST data on a web page. This works just fine. I want to customize the email body to contain all of the text data from the file...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.