AWS-使用SES寄信笔记记录

参考:
1.主要以这篇设定为主 AWS SES寄信,使用smtp+phpmailer
2.这篇主要是设定Domain与smtp setting的流程来参考 Amazon – SES 设定 Email,让使用者寄信/伺服器收信/转寄给管理者
3.连结AWS的信箱,由于AWS的SES需要帐密使用内建的php.ini去连结是没办法的,所以这里需要用PHPMailer蛮方便的,如下範例
(1).注意需要将sandbox模式解除掉,需要寄信通知官网否则你只能寄有验证过的信箱,别的信箱是不行的。
(2).使用composer安装PHPMailer,如没有安装composer请安装
官网的GitHub有範例
範例:

    use PHPMailer\PHPMailer\PHPMailer;    use PHPMailer\PHPMailer\SMTP;    use PHPMailer\PHPMailer\Exception;    // Load Composer's autoloader    require 'vendor/autoload.php';$mail = new PHPMailer(true);        //Server settings        $mail->SMTPDebug = 0;                      //这里为STMP的资讯0为关掉        $mail->isSMTP();                 $mail->Host       = '';    //贴上AWS的SES网址        $mail->SMTPAuth   = true;                                          $mail->Username   = '';    //AWS SMTP username         $mail->Password   = '';// AWS SMTP password        $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted        $mail->Port       = 25;                  //AWS SES的SMPT port        $mail->CharSet = 'utf8';//这里设定为utf8,官网下载下来的没有。从别的地方看到的,如收信看到乱码可以添加            //Recipients        $mail->setFrom('xxx@gmail.com', 'xxx');//寄信者信箱与名字        $mail->addAddress('xxx@gmail.com', 'xxx');     //收信者信箱与名字            // Content        $mail->isHTML(true);                                  // Set email format to HTML        $mail->Subject = 'Yan二手书店重置密码';        $mail->Body    = '你好,这是测试';        $mail->AltBody = '附加内容文字';        if($mail->send()){            echo '<center>                    <div class="error-msg open">                        <div class="alert alert-danger">将重置密码传入您的信箱,请进入信箱后重置密码。                    </div>                    <input onclick="window.close();" value="关闭视窗" type="button">                  </center>';//寄信成功后添加的资讯                    }else{            echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";        }

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章