Examples of application code for PHP send mail functions:
- #echo send_mail ($_post["email"), $tosubject, $_post["ErrorText"]);
- echo send_mail (' someone@126.com ', ' only a test mail for test ' php mail function ', ' a spam ');
- echo Time ();
- function Send_mail ($to, $subject = ' No subject ', $body) {
- $ Loc_host = "Mail.server" ;//Computer name, can be arbitrary
- $ SMTP_ACC = "Smp@163.com" ;//smtp Authenticated user name
- $ Smtp_pass = "Pwdpwd" ;//smtp authentication password, generally equivalent to POP3 password
- $ Smtp_host = "Smtp.163.com" ;//smtp server address, similar to smtp.tom.com
- $ from = "Smp@163.com" / //email address of sender, your e-mail address
- $ Deliver = $SMTP _acc;//reply to the specified mailbox
- $ Headers = "Content-type:text/plain; charset="gb2312"rncontent-transfer-encoding:base64 ";
- $ lb = "RN" ;//linebreak
- $ HDR = Explode ($lb, $headers);//Resolved 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:". $deliver. $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);
- if (! $fp) echo " < b > Error: b> cannot conect to ". $smtp _host." < BR > ";
- 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, 1024x768)) {
- if (substr ($result, 3,1) = = "") {break;}
- };
- if (!strstr ($req [1],substr ($result, 0, 3))) {
- $ result_str. = $req [2]. $result. " < BR > ";
- }
- }
- }
- Close connection
- @fclose ($FP);
- return $result _str;
- }
I hope this code example above will allow you to fully grasp the use of php send mail functions.
http://www.bkjia.com/PHPjc/446174.html www.bkjia.com true http://www.bkjia.com/PHPjc/446174.html techarticle example of application code for PHP send mail function: #echosend_mail ($_post[email], $tosubject, $_post[errortext]); Echosend_mail (' someone@126.com ', ' onlyatestmailfortestphpmailfunction ', ' A letter ...