Using PHP to send the source code through the socket, Support letter Authentication _php Tutorial

Source: Internet
Author: User
Use PHP to open the socket port directly to send a small program
is characterized by the use of SMTP authentication, to better use to meet the needs of ordinary users to build stations.

The entire source code is attached to this article, the same content can be downloaded to the following address.
Reprint please indicate the source.

Http://www.knowsky.com/download/phpsendmail.rar

/******************************************/
/* PHP Webmail Sender */
/* www.ebugs.org */
/* Copyright millionaire in im286.com 2005.03.07 */
* * Reprint Please specify the source * *
/******************************************/

Before use, please follow the prompts to configure the user name, password and SMTP server address, sender mailbox and so on.
Note the # is replaced by #, the www.im286.com negative Weng All rights reserved, may use freely, but retains the copyright information

Example
echo send_mail (' fuweng#im286.com ', ' letter title ', ' sending content ');


function Send_mail ($to, $subject = ' No subject ', $body) {
$loc _host = "im286"; The name of the sending computer, can be arbitrarily
$SMTP _ACC = "fuweng#im286.com"; SMTP authenticated user name, similar to fuweng@im286.com, or Fuweng
$SMTP _pass= "Password"; SMTP authentication password, generally equivalent to POP3 password
$SMTP _host= "smtp.im286.com"; SMTP server address, similar to smtp.tom.com
$from = "fuweng#im286.com"; e-mail address of sender, your email address
$headers = "Content-type:text/plain; Charset=\ "gb2312\" \r\ncontent-transfer-encoding:base64 ";
$lb = "\ r \ n"; LineBreak

$HDR = Explode ($lb, $headers); Parsed HDR
if ($body) {$bdy = Preg_replace ("/^\./", ".", Explode ($lb, $body));} The body after parsing

$SMTP = Array (
1, EHLO, looking forward to return 220 or 250
Array ("EHLO". $loc _host. $lb, "220,250", "HELO Error:"),
2, send Auth Login, look forward to return 334
Array ("AUTH LOGIN". $lb, "334", "AUTH Error:"),
3, send the BASE64 encoded user name, expect to return 334
Array (Base64_encode ($smtp _acc). $lb, "334", "Authentification Error:"),
4, send the password encoded by BASE64, expect to return 235
Array (Base64_encode ($smtp _pass). $lb, "235", "Authentification Error:"));
5. Send mail from, expecting to return 250
$SMTP [] = Array ("MAIL from: <" $from. " > ". $lb," "," "MAIL from Error:");
6, send rcpt to. Expect to return 250
$SMTP [] = Array ("RCPT to: <" $to. " > ". $lb," "," RCPT to Error: ");
7, send data, look forward to return 354
$SMTP [] = Array ("Data". $LB, "354", "Data error:");
8.0. Send from
$SMTP [] = Array ("From:". $from. $lb, "", "");
8.2. Send To
$SMTP [] = Array ("To:". $to. $lb, "", "");
8.1, send the title
$SMTP [] = Array ("Subject:". $subject. $lb, "", "");
8.3. Send Other header content
foreach ($hdr as $h) {$SMTP [] = Array ($h. $lb, "", "");}
8.4, send a blank line, end header send
$SMTP [] = Array ($lb, "", "");
8.5. Sending the subject of the letter
if ($bdy) {foreach ($bdy as $b) {$SMTP [] = Array (Base64_encode ($b. $lb). $lb, "", "");}}
9, send "." Indicates the end of the letter, expecting to return 250
$SMTP [] = Array (".". $LB, "+", "DATA (end) Error:");
10, send quit, quit, look forward to return 221
$SMTP [] = Array ("Quit". $lb, "221", "Quit Error:");

Open the SMTP server port
$fp = @fsockopen ($smtp _host, 25);
if (! $fp) echo "Error: cannot conect to". $smtp _host. "
";
while ($result = @fgets ($fp, 1024x768)) {if (substr ($result, 3,1) = = "") {Break;}}

$result _str= "";
Sending commands/Data in an SMTP array
foreach ($smtp as $req) {
Send Message
@fputs ($fp, $req [0]);
If you need to receive server return information,
if ($req [1]) {
Receive information
while ($result = @fgets ($fp, 1024)) {
if (substr ($result, 3,1) = = "") {break;}
};
if (!strstr ($req [1],substr ($result, 0, 3))) {
$result _str.= $req [2]. $result. "
";
}
}
}
Close connection
@fclose ($FP);
return $result _str;
}
?>

http://www.bkjia.com/PHPjc/313768.html www.bkjia.com true http://www.bkjia.com/PHPjc/313768.html techarticle using PHP to open the socket port directly to send the small program is characterized by the use of SMTP authentication, to better use to meet the general needs of users to build stations. The whole source is attached to this article, the same content ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.