Showing posts with label Email. Show all posts
Showing posts with label Email. Show all posts

Monday 16 March 2015

How to send an email using Email Template in Zend Framework

How to send an email using Email Template in Zend Framework

Email functionalities in websites is very common and used in mostly in all web application. Whether it is registration process or Order detail, we need to send an email to your valuable client.

To send the email using Email Template follow the following steps
1. First collect all the data which you want to send in Email like first name, last name etc.
$emailTemplateData = array('fname'=>'Web Technology','lname'=>'Experts Notes');


2. Create a Folder with name emails, where you can put the email templates files.
Email template Location: application/views/scripts/emails


3. Create a template with name registration.phtml  for registration Email and add following contents.
First name:  echo $data['fname'];  
Last name:   echo $data['fname'];  
Folder Location: application/views/scripts/emails
Don't forget to add php scripts for php variable
Im just giving you an working code, you can add lot of variables as you need.


Add following code from where you want to send an email
$subject ='This is subject';
$view = new Zend_View();
$view->addScriptPath(APPLICATION_PATH . '/views/scripts/emails');
$view->data = $emailTemplateData; //$emailTemplateData must have the values which you are using in registration.phtml
$emailHtml = $view->render('registration.phtml');
$mail = new Zend_Mail();
$mail->setBodyHtml($emailHtml);
$mail->setSubject($subject);              
$mail->setFrom("support@example.com", "From domain.com");
$mail->send();


If you get an issue regarding this post, Please comment below. we will try to fix your problem.




Thursday 19 February 2015

How to send Attachment in Email in zend framework1 - Send PDF File

How to send Attachment in Email in zend framework1 - Send PDF File

Sending an attachment in Email is very easy in zend framework. Attachmnet can be PDF file, image file, text and excel file etc. For Different type of attachment have different types of mime type. For example pdf mime type is "application/pdf" where gif image mime type is "image/gif".

In E-commerce website, when an order is placed by customer on the online website. Customer get the order detail in form of Order PDF File, So that he can keep offline record too.


Following code snippet is for How to attach a PDF file in Email using Zend Framework.
 
  /** Must fill Following detail * */
        $emailTo = 'receipts@no-spam.ws';
        $emailToName = 'receipts Name';
        /** Must fill Following detail * */
        $emailSubject = 'This is subject';
        $emailBody = 'This is HTML Email Body';
        $fromEmail = 'fromemail@no-spam.ws';
        try {
            $config = array(
                'ssl' => 'tls',
                'auth' => 'login',
                'username' => 'SMTP_USERNAME',
                'password' => 'SMTP_PASSWORD'
            );
            $transport = new Zend_Mail_Transport_Smtp('SMTP_HOST', $config);

            $mail = new Zend_Mail();
            $mail->setBodyHtml($emailBody);
            $mail->setFrom($fromEmail);
            $mail->addTo($emailTo, $emailToName);
            $mail->setSubject($emailSubject);
            
            /**PDF Add Attachment **/
            $attachment = new Zend_Mime_Part('path to pdf file');
            $attachment->type        = 'application/pdf';
            $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
            $attachment->encoding = Zend_Mime::ENCODING_BASE64;
            $attachment->filename    = 'order.pdf';
            $mail->addAttachment($attachment);
            /** Add Attachment **/            

            if ($mail->send($transport)) {
                echo 'Sent successfully';
            } else {
                echo 'unable to send email';
            }
        } catch (Exception $e) {
            echo $e->getMessage();
        }



Different Types of Attachment 



Tuesday 17 February 2015

How to send Email in wordpress

How to send Email in wordpress

In Websites, we need to send email on Registration, Forget password, order to our Clients/Customer. If your email template is ready Sending email is a very quick step in WordPress, but sometimes developer gets confused due to not available of correct email sending code.

In this post, We will give you code snippet. This code snippet will send email. You can set the receipt, subject, description, reply-to and header  in email.

$receipt = "user@no-spam.ws"; 
$subject = "This is subject";
$content = 'This is conent of the email.


http://www.web-technology-experts-notes.in';
/** Set the Reply -optional field **/
$headers = array(
 'Reply-To' => "replyto@no-spam.ws"
);
/** Set the Reply -optional field **/


/** Send the Html email - optional field **/
add_filter( 'wp_mail_content_type', 'set_html_content_type' );
/** Send the Html email - optional field **/

$status = wp_mail($receipt, $subject, $content, $headers);

if($status){
echo 'Sent Successfully';
}else{
echo 'Not send';
}
  


If above any query regarding above code, Please comment!.


Monday 9 February 2015

How to send Email in Zend Framework - HTML Email

How to send Email in Zend Framework - HTML Email


In websites, We send email to our clients for Following:
- Registration Email
- Forget Password
- Change Password
- Notification Email
- Newsletter
- Order completed
- Order In transist
- Order deliver Successfully


Following code, Which can be used to send email in Zend-Framework (HTML EMAIL).
 
/** Must fill Following detail * */
        $emailTo = 'receipts@no-spam.ws';
        $emailToName = 'receipts Name';
        /** Must fill Following detail * */
        $emailSubject = 'This is subject';
        $emailBody = 'This is HTML Email Body';
        $fromEmail = 'fromemail@no-spam.ws';
        try {
            $config = array(
                'ssl' => 'tls',
                'auth' => 'login',
                'username' => 'SMTP_USERNAME',
                'password' => 'SMTP_PASSWORD'
            );
            $transport = new Zend_Mail_Transport_Smtp('SMTP_HOST', $config);

            $mail = new Zend_Mail();
            $mail->setBodyHtml($emailBody);
            $mail->setFrom($fromEmail);
            $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();
        }

Above code is For html email, You can use html tags like bold, italic, table etc for sending rich text email.


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: