iT邦幫忙

0

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}";
        }

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言