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.
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.
9lessons labs mail server report
Postageapp.com is an email management application.
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>
hey!! amazing thx!! bit question buddy what tool u use for create the first image diagram (postage.png) have a nice day
ReplyDeletegreat ty.
ReplyDeleteI did not know postageapp.com. Thank you.
ReplyDeleteRegarding using google as smtp, please note that they limit how many mails you can send pr day. As far as I remember the limit is 500 pr. day for free accounts.
teşekkürler dersiniz için
ReplyDeletewhy when i send the email....the subject didn't come out? the subject will be empty...
ReplyDeleteinstead of get the subject from POST i'm also try to set the subject manually like this but still cannot work..
if($_POST['to'])
{
$to = $_POST['to'];
$subject = "Membership Activation";
$message = $_POST['message'];
$mail_body = array(
'text/plain' => $message,
'text/html' => $message
);
$ret = PostageApp::mail($to, $subject, $mail_body);
}
I use the phpMailer Class. So I connect directly to Gmail when coding and just comment a few lines when online.
ReplyDeleteI hope you find this usefull.
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->From = $webmaster_email;
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->Subject = "This is the subject";
$mail->Body = "Hello, World";
$mail->Send();
Download:
http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/
Great blog by the way.
good
ReplyDeleteI want to create one for my site to deliver updated look nice i will try
ReplyDeletevery nice tutorial.., usefull to me.. thanks
ReplyDeletesuperb post. good work..
ReplyDeletehttp://www.itechaleart.com/
we can use this method from XAMP localhost?
ReplyDeleteI got this error how can i rectify it.
ReplyDeleteUndefined variable: HTTP_HOST in C:\wamp\www\mail1\SMTPclass.php on line 30
how to configure SMTP in gmail account?? can we use this code from XAMP localhost???
ReplyDelete