HOWTO:AWS EC2 + AWS SES 迸出 Mail Server


  1. Simple Email Service


  2. Simple PHP mail script



在這之前 我已經申請好了EC2以及取得Access Key和Secret Key

  1. 申請SES服務

  2. 點選verify a New Sender

  3. 到你剛剛輸入的信箱 認證一下!

  4. 登入到你的EC2,然後到htdocs底下 (因為我是用SUSE)

     cd /src/www/htdocs/ 
  5. 開始先寫個index.html -> vim index.html

     <!DOCTYPE html>
     <head><title>Send Mail to YOURSELF</title></head>
     <form action="mail.php" method="POST">
     <input type="text" name="email" size=40>
     <input type="text" name="subject" size=40>
     <textarea cols=40 rows=10 name="message"></textarea>
     <p><input type="submit" value=" Send ">
  6. 在寫個mail.php -> vim mail.php

     <head><title>PHP Mail Sender Test</title></head>
     $ses = new SimpleEmailService('你在AWS使用的Access Key', '你在AWS使用的Secret Key');
     $m = new SimpleEmailServiceMessage();
     /* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
     $email = $_REQUEST['email'];
     $subject = $_REQUEST['subject'];
     $message = $_REQUEST['message'];
     /* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
     if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
     echo "<h4>Invalid email address</h4>";
     echo "<a href='javascript:history.back(1);'>Back</a>";}
     elseif ($subject == "") {
     echo "<h4>No subject</h4>";
     echo "<a href='javascript:history.back(1);'>Back</a>";}
     /* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
  7. 在把剛剛下載下來的PHP檔放上去

    你可以用scp 或是 直接複製貼上 …等

  8. 小功告成!

ps. 因為我有出現curl.init() error的問題

我發現可能是因為我沒有安裝 php5-curl 所以中間我有灌了點東西

zypper ref
zypper install php5-crul  

灌完之後就把apache server重開

/etc/init.d/apache2 restart


Google Analytics Alternative 三级在线