Sunday, June 24, 2012

Free SMTP Mail Server for Your Web Application.

Free SMTP Mail Server for Your Web Application.
Free SMTP Connect
postageapp_cofig.php
Here you have to add project API key.
<?php
# Setup Postage configuration
if(!defined('POSTAGE_HOSTNAME')) define ('POSTAGE_HOSTNAME', 'http://api.postageapp.com');
if(!defined('POSTAGE_API_KEY')) define ('POSTAGE_API_KEY', 'your project API key');
?>

Free Gmail SMTP Mail Server Configuration 
Click -> Add mail servers - to configure with your Gmail username and password.
Free SMTP Connect

postageapp_class.php
<?php
require_once('postageapp_config.php');

class PostageApp
{
// Sends a message to Postage App
function mail($recipient, $subject, $mail_body, $header, $variables=NULL) {
$content = array(
'recipients' => $recipient,
'headers' => array_merge($header, array('Subject' => $subject)),
'variables' => $variables,
'uid' => time()
);
if (is_string($mail_body)) {
$content['template'] = $mail_body;
} else {
$content['content'] = $mail_body;
}
return PostageApp::post(
'send_message', 
json_encode(
array(
'api_key' => POSTAGE_API_KEY, 
'arguments' => $content
)
)
);
}
// Makes a call to the Postage App API
function post($api_method, $content) {
$ch = curl_init(POSTAGE_HOSTNAME.'/v.1.0/'.$api_method.'.json');
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
curl_setopt($ch, CURLOPT_POST, 1);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output);
}
}
?>

SMTPtest.php
Sample page to sending test email. More information please visit postageapp.com
<?php
require_once('postageapp_class.php');
if($_POST['to'])
{
$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mail_body = array(
'text/plain' => $message,
'text/html' => $message
);
$ret = PostageApp::mail($to, $subject, $mail_body);

}
?>

<form method="post" action="">
to:<input type="text" name="to" /><br/>
sub:<input type="text" name="subject" /><br/>
message:<textarea name="message" ></textarea><br/>
<input type="submit" value="Send"/>
</form>

No comments:

Post a Comment