dongwanqiang_2017 2017-04-17 13:58
浏览 59
已采纳

Amazon SES在codeigniter中发送带附件的电子邮件

I am trying to send an email with attachment using Amazon SES.

Here is what I am doing:

<?php
$file_path = DOC_ROOT.'/report/';
$myfile    = $file_path.$filename;
$file_size = filesize($myfile);
$handle    = fopen($myfile, "r");
$content   = fread($handle, $file_size);

$subject = 'Report';
$content = chunk_split(base64_encode($content));
$header  = "";

$message = 
  '<html>
        <head><title></title></head>
        <body>
            <p>Hello '.$vEmail.',</p></br>
            <p>Please find attached file.</p>    
            <p>Regards,</p>
            <p>'.MAINTITLE.'</p></br>
        </body>
        </html>';  

$ses = new Simpleemailservice(AWS_ACCESSKEY, AWS_SECRET);
$from = FROM_EMAIL_SES;    
$uid = md5(uniqid(time()));

$header = "From: ".$from." <".$from.">
";
$header .= "To: ".$vEmail."
";
$header .= "Subject: ".$subject."
";
$header .= "MIME-Version: 1.0
";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"

";
$header .= "This is a multi-part message in MIME format.
";
$header .= "--".$uid."
";
$header .= "Content-type:text/html; charset=iso-8859-1
";
$header .= "Content-Transfer-Encoding: 7bit

";
$header .= $message."

";
$header .= "--".$uid."
";
$header .= "Content-Type: text/csv; name=\"".$myfile."\"
";
$header .= "Content-Transfer-Encoding: base64
";
$header .= "Content-Disposition: attachment; filename=\"".$myfile."\"

";
$header .= $content."

";
$header .= "--".$uid."--";

$msg['RawMessage']['Data'] = base64_encode($header);
$msg['RawMessage']['Source']= $from;
$msg['RawMessage']['Destinations'] = $vEmail;
fclose($handle);

$result = $ses->sendRawEmail($msg);
$msg_id = $result->get('MessageId');
?>

the error I am getting:

Fatal error: Call to a member function setParameter() on a non-object in /libraries/Simpleemailservice.php on line 267

I found this Answer but it didn't help.

  • 写回答

1条回答 默认 最新

  • douyi8732 2017-04-17 16:56
    关注

    there could be a problem with initialization, You can check the API documentation for details.

    I can give you a better option with PHPMailer and Amazon SNS.You can check out the code that I gave below. https://gist.github.com/kilitbilgi/f697898339e3e751c32c735ac9c4ba1d

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记