标签:
参见代码:
<?php $mail = new SaeMail(); $f = new SaeFetchurl(); $img_data = $f->fetch( ‘http://ss7.sinaimg.cn/bmiddle/488efcbbt7b5c4ae51ca6&690‘ ); $mail->setAttach( array( ‘my_photo‘ => $img_data ) ); $ret = $mail->quickSend( ‘377087477@qq.com‘ , ‘邮件标题‘ , ‘邮件内容‘ , ‘你的邮箱地址‘ , ‘你的邮箱密码‘ ); //发送失败时输出错误码和错误信息 if ($ret === false) var_dump($mail->errno(), $mail->errmsg()); $mail->clean(); // 重用此对象 $ret = $mail->quickSend( ‘377087477@qq.com‘ , ‘邮件标题‘ , ‘邮件内容‘ , ‘SMTP账号‘ , ‘SMTP密码‘ , ‘SMTP服务器地址‘ , 25 ); // 指定smtp和端口 //发送失败时输出错误码和错误信息 if ($ret === false) var_dump($mail->errno(), $mail->errmsg()); ?>
可以访问:http://lazydemo.sinaapp.com/mail/mail_sae.php(不要大量点击)
大量用户反应延迟比较严重,下面推荐一个我自用的函数类,几乎没有延迟,放出来给大家使用,
<?php /* * @author lazypeople<hfutming@gmail.com> * @function send mail * @package lazypeople */ function send_mail_lazypeople($to, $subject = ‘Your register infomation‘, $body) { $loc_host = "SAE"; $smtp_acc = "你的账号地址"; $smtp_pass="你的密码"; $smtp_host="SMTP地址"; $from="你的邮箱地址"; $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,"250","MAIL FROM error: "); $smtp[] = array("RCPT TO: <".$to.">".$lb,"250","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,"250","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(‘377087477@qq.com‘,‘hello‘,‘hello‘);//测试 ?>
http://lazydemo.sinaapp.com/mail/mail.zip
Sina App Engine(SAE)入门教程(9)- SaeMail(邮件)使用
标签:
原文地址:http://www.cnblogs.com/little-aladdin/p/4904140.html