Monday, 2 February 2015

Send Email from Gmail SMTP using Zend Framework

Send Email from Gmail SMTP using Zend Framework

In Website we need to send email on Registration, Forget , Order email to our Clients/Customer.
We want email should be deliver timely in inbox folder not in junk/spam folder.
For this we have to use SMTP Server.

GMAIL SMTP Server is free to use, if you have valid Gmail account.

Just the following code to send email from your Gmail Account.
/** Must fill Following detail * */
$yourGmailAccountUsername = 'youremail@gmail.com';
$yourGmailAccountPassword = '********';
$emailTo = 'arun.compute@gmail.com';
$emailToName = 'receiptsName';
/** Must fill Following detail * */

/** Optional Detail * */
$emailBody = 'This is body text';
$emailSubject = 'This is subject';
/** Optional Detail * */

try {
    $config = array('ssl' => 'tls',
        'auth' => 'login',
        'username' => $yourGmailAccountUsername,
        'password' => $yourGmailAccountPassword);

    $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);


    $mail = new Zend_Mail();

    $mail->setBodyHtml($emailBody);
    $mail->setFrom($yourGmailAccountUsername);
    $mail->addTo($emailTo, $emailToName);
    $mail->setSubject($emailSubject);
    if ($mail->send($transport)) {
        echo 'Sent successfully';
    } else {
        echo 'unable to send email';
    }
} catch (Exception $e) {
    echo $e->getMessage();
}

If you get similar to following Error
Please log in via your web browser and then try again.
5.7.14 Please log in via your web browser and then try again. 5.7.14 Learn more at 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 fr13sm3613053pdb.81

If Yes,
whether you have "turned on 2-Step Verification" OR Google need Verification that you want to use your gmail as SMTP credential.
you can fix this in couple of minutes using below link:
https://support.google.com/mail/answer/78754

If any issue, please comment below in comment box:




Friday, 30 January 2015

How to display HTML Correctly in Email?

How to display HTML Correctly in Email?

When we send a email to users from web application, many times we see HTML email is distorted in Gmail, Yahoo, Iphone and Ipad etc.

 If you want to removed such type of issue, then keep following points in mind while creating html template. 


  Use tables for layout
<table>
<!--- html code -->
<!--- html code -->
</table>



Set the width in each cell
<table border="0" cellpadding="10" cellspacing="0">
 <tbody>
<tr>
  <td width="50">Sr</td>
  <td width="100">Name</td>
  <td width="100">Email</td>
  <td width="100">Billing Date</td>
 </tr>
</tbody></table>



Use a container table for body background colors
<table border="0" cellpadding="10" cellspacing="0">
<tbody>
<tr>
<td bgcolor="#000000">Background Color </td>
</tr>
</tbody></table>



Avoid unnecessary whitespace and in table
<table border="0" cellpadding="10" cellspacing="0">
<tbody>
<tr>
<td></td>
</tr>
</tbody></table>



Use "nbsp;" for doubly space


Avoid shorthand, use as below
 font-weight: bold;
 font-size: 1em;
 line-height: 1.2em;
 font-family: georgia,serif;


Always use inline CSS
<div style="color: red;">
Inline CSS</div>



Set link color in following way
<a href="http://web-technology-experts-notes.in/" style="color: black;"><span style="color: magenta;">this is a link</span></a>



Images in HTML emails
a. Avoid spacer images
b. Always include the dimensions of your image
c. Avoid PNGs image
d. Always add alt text in image attribute


Never use floats attribute 


Check CSS support in email
https://www.campaignmonitor.com/css/