SMTPsock application-send an email using php

Source: Internet
Author: User
Server_name can use php own dns resolution function, the following is the core demo, winNT, mailserverisImail, php3.0.6 need to modify php3.ini open imap module, in linux to compile php -- with-IMAPSyntaxHighlighter.all ();

Server_name can use php's own dns resolution function,
The following is a core demonstration: winNT, mail server is Imail, php3.0.6
You need to modify php3.ini to open the imap module and compile php -- with-IMAP on linux.

Function send_email ($ to, $ from, $ subject, $ message ){
Global $ SERVER_NAME;
$ Fp = fsockopen ($ SERVER_NAME, 25 );
If ($ fp ){

Echo "connected ";

Set_socket_blocking ($ fp, false );
$ Output = fgets ($ fp, 2500 );

Echo $ output;

If (! Ereg ("^ 220", $ output )){
Exit ();
} Else {

Echo "talking ";

// Set_socket_blocking ($ fp, true );
Fputs ($ fp, "HELO $ from_domain ");
$ Output = fgets ($ fp, 2000 );

Echo $ output;

Fputs ($ fp, "mail from: <$ from> ");
$ Output = fgets ($ fp, 2000 );

Echo $ output;

Fputs ($ fp, "rcpt to: <$ to> ");
$ Output = fgets ($ fp, 2000 );

Echo $ output;

Fputs ($ fp, "DATA ");
Fputs ($ fp, "To: $ ");


Fputs ($ fp, "From: $ from ");
Fputs ($ fp, "Subject: $ subject ");
Fputs ($ fp, "$ message .");
Fputs ($ fp, "QUIT ");
}
}
Fclose ($ fp );
}

$ SERVER_NAME = "127.0.0.1 ";
$ From_domain = "ws ";
$ To = "daiger@xifeng.com ";
$ From = "wangsu@xifeng.com ";
$ Subject = "test SMTP through PHP Chinese ";
$ Message = "Send email via PHP smtp connectionsnnnothing happenesn Chinese
Chinese ";

Send_email ($ to, $ from, $ subject, $ message );
Echo "OK lah ";
?>

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.