php tutorial to send mail and pop3 mail login code
function send_msg ($ to, $ subject, $ body) {
$ send_addr = 'admin@test.com'; // sender's address
$ header = "from: admin <". $ send_addr. "> rn"; // Set the email header
ini_set ('sendmail_from', $ send_addr);
mail ($ to, $ subject, $ body, $ header);
}
pop3 email login
function pop3_login ($ host, $ username, $ password)
{
global $ debug;
if (empty ($ host)) {
return false;
}
if ($ debug)
echo "open hostname:". $ host. ", port:". $ port. "n";
$ conn = @fsockopen ($ host, 110, $ err_no, $ err_str, 5);
if (! $ conn) {
return false;
}
$ ret_info = fgets ($ conn, 1024);
if (substr ($ ret_info, 0,3) == "+ ok") {
if (login ($ conn, $ username, $ password)) {
return true;
}
}
return false;
}
smtp login authentication function
function smtp_login ($ host, $ username, $ password)
{
global $ debug;
if (empty ($ host)) {
return false;
}
if ($ debug)
echo "open hostname:". $ host. ", port:". $ port. "n";
$ conn = @fsockopen ($ host, 25, $ err_no, $ err_str, 5);
if (! $ conn) {
return false;
}
$ ret_info = fgets ($ conn, 1024);
if (substr ($ ret_info, 0,3) == "220") {
fputs ($ conn, "helo localhostrn");
if (substr (fgets ($ conn, 1024), 0,3) == "250") {
if (login ($ conn, $ username, $ password, 25)) {
return true;
}
}
}
return false;
}
imap login verification function
function imap_login ($ host, $ username, $ password)
{
global $ debug;
if (empty ($ host)) {
return false;
}
if ($ debug)
echo "open hostname:". $ host. ", port:". $ port. "n";
$ conn = @fsockopen ($ host, 143, $ err_no, $ err_str, 5);
if (! $ conn) {
return false;
}
$ ret_info = fgets ($ conn, 1024);
if (strpos ($ ret_info, "ok")) {
fputs ($ conn, "a001 login $ username $ passwordrn");
$ ret = fgets ($ conn, 1024);
if (strpos ($ ret, "login ok")) {
return true;
}
}
return false;
}