Last active
December 6, 2015 16:45
-
-
Save hunnycode/f5f474721f0812a99edb to your computer and use it in GitHub Desktop.
BluemixとSendGridを使って、メール送信アプリを作ってみた。 ref: http://qiita.com/joohounsong/items/96dfb8f5099e581f5a44
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cf login -u [Bluemix Login Mail Add] -s [Bluemix Space] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cf api https://api.ng.bluemix.net |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>PHP Starter Application</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<link rel="stylesheet" href="style.css" /> | |
</head> | |
<body> | |
<table> | |
<tr> | |
<td style='width: 30%;'> | |
<img class='newappIcon' src='images/newapp-icon.png'> | |
</td> | |
<td> | |
<h1 id = "message"><?php echo "メール送信"; ?></h1> | |
</td> | |
</tr> | |
<tr> | |
<td> | |
<form method="POST" action="./send.php"> | |
【送信先】<br><input type="text" name="email"><br> | |
【タイトル】<br><input type="text" name="subject"><br> | |
【本文】<br><textarea name="body" cols="50" rows="5">送信する本文を入力してください。</textarea><br> | |
<input type="submit" name="btn1" value="送信"> | |
</form> | |
</td> | |
</tr> | |
</table> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$to = $_POST['email']; | |
$from = "送信元メールアドレス"; | |
$subject = $_POST['subject']; | |
$body = $_POST['body']; | |
$url = 'https://api.sendgrid.com/'; | |
$user = 'SendGrid username'; | |
$pass = 'SendGrid Password'; | |
$params = array( | |
'api_user' => $user, | |
'api_key' => $pass, | |
'to' => $to, | |
'subject' => $subject, | |
'text' => $body, | |
'from' => $from, | |
); | |
$request = $url.'api/mail.send.json'; | |
$session = curl_init($request); | |
curl_setopt ($session, CURLOPT_POST, true); | |
curl_setopt ($session, CURLOPT_POSTFIELDS, $params); | |
curl_setopt($session, CURLOPT_HEADER, false); | |
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); | |
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); | |
$response = curl_exec($session); | |
curl_close($session); | |
print_r($response); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd src/blue-send-mail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cf push blue-send-mail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment