Sina App Engine (SAE) Introductory Tutorial (9)-saemail (mail) use

Source: Internet
Author: User

Resources:
    • SAE Mail API documentation
How to use?

See Code:

<?PHP$mail=NewSaemail ();$f=NewSaefetchurl ();$img _data=$f->fetch (' http://ss7.sinaimg.cn/bmiddle/488efcbbt7b5c4ae51ca6&690 ' );$mail->setattach (Array(' My_photo ' =$img _data ) );$ret=$mail->quicksend (' [email protected] ', ' mail header ', ' email content ', ' Your email address ', ' Your email password ' );//Output error codes and error messages when sending failsif($ret===false)        Var_dump($mail->errno (),$mail-errmsg ());$mail->clean ();//reuse This object$ret=$mail->quicksend (' [email protected] ', ' mail header ', ' email content ', ' SMTP account ', ' SMTP password ', ' SMTP server address ', 25);//specify SMTP and port//output error codes and error messages when sending failsif($ret===false)        Var_dump($mail->errno (),$mail-errmsg ());?>

Access to: http://lazydemo.sinaapp.com/mail/mail_sae.php (do not click heavily)
A large number of user response delay is serious, the following recommended a my own function class, almost no delay, put out for everyone to use,

<?PHP/** @author lazypeople<[email protected]>* @function send mail* @package lazypeople*/functionSend_mail_lazypeople ($to,$subject= ' Your register infomation ',$body) {    $loc _host= "SAE"; $smtp _ACC= "Your account address"; $smtp _pass= "Your password"; $smtp _host= "SMTP Address"; $from= "Your e-mail address"; $headers= "Content-type:text/plain; Charset=\ "utf-8\" \r\ncontent-transfer-encoding:base64 "; $lb= "\ r \ n";//LineBreak            $HDR=Explode($lb,$headers); if($body) {$bdy=Preg_replace("/^\./","..",Explode($lb,$body));}//?????? Body    $SMTP=Array(          Array("EHLO".$loc _host.$lb, "220,250", "HELO Error:"),Array("AUTH LOGIN".)$lb, "334", "AUTH Error:"),Array(Base64_encode($smtp _ACC).$lb, "334", "Authentification Error:"),Array(Base64_encode($smtp _pass).$lb, "235", "Authentification Error:")); $SMTP[] =Array("MAIL From: <".)$from." > ".$lb, "$", "MAIL from Error:"); $SMTP[] =Array("RCPT to: <".$to." > ".$lb, "$", "RCPT to Error:"); $SMTP[] =Array("DATA".)$lb, "354", "DATA Error:"); $SMTP[] =Array("From:".)$from.$lb,"",""); $SMTP[] =Array("To:".)$to.$lb,"",""); $SMTP[] =Array("Subject:".)$subject.$lb,"",""); foreach($HDR  as $h) {$SMTP[] =Array($h.$lb,"","");} $SMTP[] =Array($lb,"",""); if($bdy) {foreach($bdy  as $b) {$SMTP[] =Array(Base64_encode($b.$lb).$lb,"","");}} $SMTP[] =Array(".".$lb, "$", "DATA (end) Error:"); $SMTP[] =Array("QUIT".)$lb, "221", "QUIT Error:"); $fp= @Fsockopen($smtp _host, 25); if(!$fp)Echo"Error:cannot conect to".$smtp _host."";  while($result= @fgets($fp, 1024)) {if(substr($result, 3, 1) = = "") { Break; }} $result _str=""; foreach($SMTP  as $req){          @fputs($fp,$req[0]); if($req[1]){                 while($result= @fgets($fp, 1024)){                    if(substr($result, 3, 1) = = "") { Break; }                }; if(!strstr($req[1],substr($result, 0,3))){                    $result _str.=$req[2].$result.""; }          }    }    @fclose($fp); return $result _str;} Send_mail_lazypeople (' [email protected] ', ' hello ', ' hello ');//Test?>
The tutorial source Packaging

Http://lazydemo.sinaapp.com/mail/mail.zip

Sina App Engine (SAE) Introductory Tutorial (9)-saemail (mail) use

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.