Ads

May 12, 2013

Free SMTP Mail Server for Your Web Application


How to configure free SMTP mail server to your web project with Gmail account. I had implemented at 9lessons labs to sending email notifications using my gmail account. I did this with support of postageapp.com - the easier way to send email from web applications. It is simple and very easy to configure so use it and add email support to your web application.

Eg:labs.9lessons.info - Email notifications forgot password, comments and connecting friend.
Free SMTP Connect

First you have to create account at postageapp.com. The next thing you have to create a project.

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

9lessons labs mail server report
Postageapp.com is an email management application.
Free SMTP Connect

Postageapp PHP source download files : Postageapp PHP example

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:

Most Popular Posts