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

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 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动