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 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?