Blogs Hub

by AskGif | Aug 26, 2019 | Category :coding

Implementing Amazon Simple Email Service SMTP using PHP Mailer.

Implementing Amazon Simple Email Service SMTP using PHP Mailer.

<p>I have been working with askgif application hosted at Amazon Web Services. A few days back I had enabled email notification system using Amazon Simple Email Service SMTP implemented with PHP Mailer class, I hope the following tutorial will help you to enable email notification system for your web projects.</p> <p>The tutorial contains five PHP files in that three are PHPmailer files other SMTP config files.</p> <pre class="language-markup"><code>class.phpmailer.php // PHP Mailer library class.smtp.php class.pop3.php Send_Mail.php // SMTP configer index.php // Start Page</code></pre> <p>&nbsp;</p> <p>Send_Mail.php</p> <p>Here you have to give Amazon SES SMTP credentials.&nbsp;</p> <pre class="language-javascript"><code>&lt;?php function Send_Mail($to,$subject,$body) { require 'class.phpmailer.php'; $from = "from@email.com"; $mail = new PHPMailer(); $mail-&gt;IsSMTP(true); // SMTP $mail-&gt;SMTPAuth = true; // SMTP authentication $mail-&gt;Mailer = "smtp"; $mail-&gt;Host= "tls://email-smtp.us-east.amazonaws.com"; // Amazon SES $mail-&gt;Port = 465; // SMTP Port $mail-&gt;Username = "Amazon SMTP Username"; // SMTP Username $mail-&gt;Password = "Amazon SMTP Password"; // SMTP Password $mail-&gt;SetFrom($from, 'From Name'); $mail-&gt;AddReplyTo($from,'askgif Labs'); $mail-&gt;Subject = $subject; $mail-&gt;MsgHTML($body); $address = $to; $mail-&gt;AddAddress($address, $to); if(!$mail-&gt;Send()) return false; else return true; } ?&gt;</code></pre> <p>&nbsp;</p> <p>index.php</p> <p>Here called Send_Mail function and passing to, subject and body values</p> <pre class="language-javascript"><code>&lt;?php require 'Send_Mail.php'; $to = "to@gmail.com"; $subject = "Test Mail Subject"; $body = "Hi&lt;br/&gt;Test Mail&lt;br/&gt;Amazon SES"; // HTML tags Send_Mail($to,$subject,$body); ?&gt;</code></pre> <p>&nbsp;</p> <p>Gmail SMTP</p> <p>You have to modify the following line in above Send_Mail.php code, Gmail allows per day only 250 mail limit.&nbsp;</p> <pre class="language-javascript"><code>$mail-&gt;Host= "tls://smtp.gmail.com"; // GMail SMTP $mail-&gt;Port = 465; // SMTP Port $mail-&gt;Username = "Username@gmail.com"; // SMTP Username $mail-&gt;Password = "Gmail Password"; // SMTP Password</code></pre>

read more...