Home > php教程 > php手册 > body text

php 发送邮件与pop3邮件登录代码

WBOY
Release: 2016-05-25 16:49:36
Original
2507 people have browsed it

php发送邮件与pop3邮件登录代码

<?php
function send_msg($to, $subject, $body) {
    $send_addr = &#39;admin@test.com&#39;; //发送人地址
    $header = "from: admin <" . $send_addr . ">rn"; //设置email头
    ini_set(&#39;sendmail_from&#39;, $send_addr);
    mail($to, $subject, $body, $header);
}
?>
Copy after login

pop3邮箱登录

<?php
function pop3_login($host, $username, $password) {
    global $debug;
    if (emptyempty($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;
}
?>
Copy after login

smtp登录验证函数

function smtp_login($host, $username, $password) {
    global $debug;
    if (emptyempty($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;
}
Copy after login

imap登录验证函数

function imap_login($host, $username, $password) {
    global $debug;
    if (emptyempty($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;
}
Copy after login

               
               

教程网址:

欢迎收藏∩_∩但请保留本文链接。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!