-
- /**
- Function: Send email
- url: http://bbs.it-home.org
- */
- header("content-type:text/html;charset=utf-8");
- $smtp = array(
- "url" => ; "Email SMTP server address",
- "port" => "Email SMTP server port", // Generally 25
- "username" => "Username",
- "password" => "Password",
- "from" => "Sending address",
- "to" => "Receiving address",
- "subject" => "Test the title",
- "body" => "Test the content "
- );
- $CRLF = "rn";
- $test = "";
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $smtp['url']);
- curl_setopt($curl, CURLOPT_PORT, $smtp['port']);
- curl_setopt($curl, CURLOPT_TIMEOUT,10);
- function inlineCode($str){
- $str = trim($str);
- return $str?'=?UTF- 8?B?'.base64_encode($str).'?= ':'';
- }
- function buildHeader($headers){
- $ret = '';
- foreach($headers as $k=>$v ){
- $ret.=$k.': '.$v."n";
- }
- return $ret;
- }
- //
- $header = array(
- 'Return-path'=>'< ;'.$smtp['from'].'>',
- 'Date'=>date('r'),
- 'From'=> '<'.$smtp['from']. '>',
- 'MIME-Version'=>'1.0',
- 'Subject'=>inlineCode($smtp['subject']),
- 'To'=>$smtp['to'] ,
- 'Content-Type'=>'text/html; charset=UTF-8; format=flowed',
- 'Content-Transfer-Encoding'=>'base64'
- );
- $data = buildHeader($ header).$CRLF.chunk_split(base64_encode($smtp['body']));
- $content = "EHLO ".$smtp["url"].$CRLF; // Hello first
- $content .= "AUTH LOGIN".$CRLF.base64_encode($smtp["username"]).$CRLF.base64_encode($smtp["password"]).$CRLF; // Verify login
- $content .= "MAIL FROM:" .$smtp["from"].$CRLF; // Sending address
- $content .= "RCPT TO:".$smtp["to"].$CRLF; // Receiving address
- $content .= " DATA".$CRLF.$data.$CRLF.".".$CRLF; // Send content
- $content .= "QUIT".$CRLF; // Exit
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); / / curl receives return data
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $content);
- $test = curl_exec($curl);
- var_dump($test);
- echo "
rn";
- var_dump($ content);
- // End
- curl_close($curl);
- ?>
Copy code
It took nearly 6 hours to make the product code compatible with fsockopen and curl; I will study it when I have time. curl's smtp class for simply sending emails.
|