Skip to content

Instantly share code, notes, and snippets.

@hunnycode
Last active December 6, 2015 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hunnycode/f5f474721f0812a99edb to your computer and use it in GitHub Desktop.
Save hunnycode/f5f474721f0812a99edb to your computer and use it in GitHub Desktop.
BluemixとSendGridを使って、メール送信アプリを作ってみた。 ref: http://qiita.com/joohounsong/items/96dfb8f5099e581f5a44
cf login -u [Bluemix Login Mail Add] -s [Bluemix Space]
cf api https://api.ng.bluemix.net
<!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>
<?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);
?>
cf push blue-send-mail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment