質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

1回答

2053閲覧

AWS SES APIでお問い合わせフォーム

hyskyo

総合スコア79

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2017/04/20 10:11

編集2017/04/20 10:19

AWS SESのAPIでメール送信したくて、下記のAWSのソースコードでは問題なく送信できていますがそのAWSのソースコードをオリジナルのPHP(contact.php)で書いたソースコードに書き込んで見ましたが下記のエラ-が出てしまいました。どう見てもAWSの SES APIをオリジナルPHP(contact.php)ファイルに書き込んだのが間違っているみたいです。誰か助けてくださいませんか?

やりたいことはAWS SESのAPIを使ってお問い合わせでメール送信をを行いたいです。

下記はAWSから出してる実際のamazon-ses-sample.phpのソースコードです。これは問題なく動作しています

https://docs.aws.amazon.com/ja_jp/ses/latest/DeveloperGuide/send-using-sdk-php.html <?php // Replace path_to_sdk_inclusion with the path to the SDK as described in // http://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/basic-usage.html define('REQUIRED_FILE','vendor/autoload.php'); // Replace sender@example.com with your "From" address. // This address must be verified with Amazon SES. define('SENDER', 'noreply@example.com'); // Replace recipient@example.com with a "To" address. If your account // is still in the sandbox, this address must be verified. define('RECIPIENT', 'info@example.co.jp'); // Replace us-west-2 with the AWS region you're using for Amazon SES. define('REGION','us-west-2'); define('SUBJECT','これはテストメールです'); define('BODY','このメールはテストメールです. '); require REQUIRED_FILE; use Aws\Ses\SesClient; $client = SesClient::factory(array( 'version'=> 'latest', 'region' => REGION, 'credentials' => array( 'key' => 'xxxxxxxxxx', 'secret' => 'xxxxxxxxxxxxxxxxxx', ) )); $request = array(); $request['Source'] = SENDER; $request['Destination']['ToAddresses'] = array(RECIPIENT); $request['Message']['Subject']['Data'] = SUBJECT; $request['Message']['Body']['Text']['Data'] = BODY; try { $result = $client->sendEmail($request); $messageId = $result->get('MessageId'); echo("Email sent! Message ID: $messageId"."\n"); } catch (Exception $e) { echo("The email was not sent. Error message: "); echo($e->getMessage()."\n"); } ?>

index.html

<!DOCTYPE html> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />> <script type="text/javascript" src="contact.js"></script> </head> <body> <div id="wrap"> <form action="contact.php" method="post" name="form" onsubmit="return validate()" > <table > <tr> <th><label>お名前</label></th> <td><input type="text" name="name" value=""></td> </tr> <tr> <th><label>メールアドレス</label></th> <td><input type="text" name="email" value=""></td> </tr> <tr> <th><label>お電話番号</label></th> <td><input type="text" name="tel" value="" ></td> </tr> <tr> <th><label>お問い合わせ内容</label></th> <td><textarea name="content" cols="50" rows="10" ></textarea></td> </tr> </table> <input type="submit" value="内容を確認する" /> </p> </form> </div> </body> </html>

下記はオリジナルのソースファイルcontact.phpです:

<?php // フォームのボタンが押されたら if ($_SERVER["REQUEST_METHOD"] == "POST") { $name = $_POST["name"]; $email = $_POST["email"]; $tel = $_POST["tel"]; $content = $_POST["content"]; } // 送信ボタンが押されたら if (isset($_POST["submit"])) { //ここにAWS SES APIを追加 define('REQUIRED_FILE','vendor/autoload.php'); define('SENDER', 'noreply@example.com'); // Replace recipient@example.com with a "To" address. If your account // is still in the sandbox, this address must be verified. define('RECIPIENT', 'info@example.co.jp'); // Replace us-west-2 with the AWS region you're using for Amazon SES. define('REGION','us-west-2'); define('SUBJECT','[自動送信]'); define('BODY'," {$name} 様 =========== テスト ========== 【 お名前 】 {$name} 【 メールアドレス】 {$email} 【 電話番号 】 {$tel} 【 内容 】 {$content} " ); ?> <?php //AWS SES のAPIの追加 require REQUIRED_FILE; use Aws\Ses\SesClient; $client = SesClient::factory(array( 'version'=> 'latest', 'region' => REGION, 'credentials' => array( 'key' => 'AWXXXXXXXXXX', 'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx', ) )); $request = array(); $request['Source'] = SENDER; $request['Destination']['ToAddresses'] = array(RECIPIENT); $request['Message']['Subject']['Data'] = SUBJECT; $request['Message']['Body']['Text']['Data'] = BODY; ?> <!DOCTYPE html> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <div> <h1>確認画面</h1> <form action="contact.php" method="post"> <table class="formTable submit"> <input type="hidden" name="name" value="<?php echo $name; ?>"> <input type="hidden" name="email" value="<?php echo $email; ?>"> <input type="hidden" name="tel" value="<?php echo $tel; ?>"> <input type="hidden" name="content" value="<?php echo $content; ?>"> <tr> <th><label>お名前</label></th> <td><p><?php echo $name; ?></p></td> </tr> <tr> <th><label>メールアドレス</label></th> <td><p><?php echo $email; ?></p></td> </tr> <tr> <th><label>電話番号</label></th> <td><p><?php echo $tel; ?></p></td> </tr> <tr> <th><label>お問い合わせ内容</label></th> <td><p><?php echo nl2br($content); ?></p></td> </tr> </table> <input type="submit" name="submit" value="送信する"> <input type="button" value="戻る" onclick="history.back(-1)"> </form> </div> </body> </html>

contact.phpで下記のエラー:

Parse error: syntax error, unexpected 'use' (T_USE) in /var/www/html/contact.php on line 75

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

Bodyに書き込んで解決しました

投稿2017/04/20 12:06

hyskyo

総合スコア79

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問