首页 > 技术文章 > SaeMail使用示例

zhezh 2014-04-29 00:08 原文

SAE的官方文档:http://apidoc.sinaapp.com/sae/SaeMail.html

SaeMail类的具体实现:http://apidoc.sinaapp.com/__filesource/fsource_sae__saemail.class.php.html

官方给出的demo:

<?php
$mail = new SaeMail();
$mail->setAttach( array( 'my_photo' => '照片的二进制数据' ) );
$ret = $mail->quickSend( 'to@sina.cn' , '邮件标题' , '邮件内容' , 'smtpaccount@gmail.com' , 'password' );
 
//发送失败时输出错误码和错误信息
if ($ret === false)
        var_dump($mail->errno(), $mail->errmsg());
 
$mail->clean(); // 重用此对象
$ret = $mail->quickSend( 'to@sina.cn' , '邮件标题' , '邮件内容' , 'smtpaccount@unknown.com' , 'password' , 'smtp.unknown.com' , 25 ); // 指定smtp和端口
 
//发送失败时输出错误码和错误信息
if ($ret === false)
        var_dump($mail->errno(), $mail->errmsg());
?>

千手修改了一下,写了一个更加详细的demo:

<?php
	
	$title		=	"请点击一下链接确认账户信息";
	$content	=	"<p style=\"color:red\">确认地址:</p>
						<p><a href=\"http://qianshouatsdnu.sinaapp.com\">http://qianshouatsdnu.sinaapp.com</a></p>";
	
	$f = new SaeFetchurl();
	$img_data = $f->fetch( 'http://qianshouatsdnu-qianshou.stor.sinaapp.com/14069974591495371377.jpg' );
	$img = new SaeImage();
	$img->setData( $img_data );
	$new_data = $img->exec(); // 执行处理并返回处理后的二进制数据
	
	$my_main_address	=	"你的邮箱地址";
	$my_mail_password	=	"你的邮箱密码";
	$to_mail_address	=	"用户的邮箱地址";
	
	$mail = new SaeMail();
	$mail->setAttach( array( 'my_photo.jpg' => $new_data) );
	$mail->setOpt(array("content_type"=>"HTML"));	//设定发送的内容为html格式
	$ret = $mail->quickSend( $to_mail_address , $title , $content , $my_main_address , $my_mail_password );
	
	//发送失败时输出错误码和错误信息
	if ($ret === false)
		var_dump($mail->errno(), $mail->errmsg());
	else 
	{
		echo "send mail successfully!";
	}
	$mail->clean(); // 清理内容,以便下次使用
?>

用户收到的邮件效果图:



推荐阅读