Saturday, August 4, 2012

Sending Email with attachment in Zend Framework

<?php
require_once 'Zend/Mail.php' ; // include on header on Controller where you want use

$message='Report of last months log files Please keep in mind Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry"s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.' ;
//echo $message;die;

$subject = 'Subject of Email';

$config = array('auth' => 'login',
                'username' => 'Email Id', // To Be Required bhupendra.iec@hotmail.com
                'password' => 'xxxxxxx'); // To Be Required xxxxxxx

// SMTP must be change according to Mail Server

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

$mail = new Zend_Mail();
$mail->setType(Zend_Mime::MULTIPART_RELATED);
$mail->setBodyText($message);
$mail->setBodyHtml($message);
$mail->setFrom('bhupendra.iec@hotmail.com');
$mail->addTo('bhupendra.iec@gmail.com');
$mail->setSubject($subject);
$fileContents = file_get_contents($_FILES['resume']['tmp_name']); // To Be Required Attachement File name
$at=$mail->createAttachment($fileContents);
$at->filename = $_FILES['resume']['name']; // To Be Required Attachement File name
$mail->send($transport);
$this->_redirect("index/index/msg/suc");
?>

Friday, July 27, 2012

htaccess Redirect for PHP.

How to redirect webpages

The .htaccess file is a small text document that generally sits in the same location as your index.php or index.htm pages. It gives you the ability to interact with Apache on an individual domain-to-domain and directory-to-directory basis.
You can place the htaccess file anywhere where you'd like to control the flow of visitors. So for instance you can protect directories and redirect the traffic visiting those pages. This page will show you how to use the .htaccess file to redirect your visitors in different ways. Note that this is a powerful system file, if the syntax is incorrect in anyway, it could render your site unusable. Always take a backup.

Redirect to another page

To redirect one page to another page:
Redirect /old-index.html http://www.mynewwebsite.com/foldername/new-index.html

Redirect to another website

To redirect an entire website from one url to another:
Redirect 301 / http://www.mynewwebsite.com

Redirect index to subdirectory

To redirect a page to a subdirectory:
Redirect /index.html http://www.mynewwebsite.com/foldername

Redirect filepaths

To redirect a filepath to another filepath:
Redirect /foldername/filename.html http://www.mynewwebsite.com/foldername2/filename.html

To change file extention

If you've changed your pages from .html to .php:
RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php

Specifying folder default page

To change the default webpage loaded by the server:
DirectoryIndex index.php

Redirect www to non-www

To redirect http://www.mysite.com to http://mysite.com:
RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.mynewwebsite\.com$ [NC]

RewriteRule ^(.*)$ http://mynewwebsite.com/$1 [L,R=301]

Redirect non-www to www

To redirect http://mysite.com to http://www.mysite.com:
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.mynewwebsite\.com$ [NC]

RewriteRule ^(.*)$ http://www.mynewwebsite.com/$1 [L,R=301]

Give 307 'Site Under Maintenance' Header on all webpage requests

To return a 307 Site Under Maintenance header to those visiting the site. Create a temporary file called 307.php and inside it place the message to give to your visitors and upload it to your public root directory.
Next create a totally separate .htaccess file called .htaccess.307 with the following text:
RewriteEngine On

RewriteBase /

# Before using this htaccess, you have to change this digits to match your

# own IP address: This will keep you with access to the site. as long as

# your IP doesn't change: http://whatismyip.com



RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123$



# The last 2 lines take the site offline. the basically say if: page request is

# NOT 307.php, show 307.php but only once. Stops it from looping endlessly.

RewriteCond %{REQUEST_URI} !^/307\.php$



# The browser gets this bit, so you need the full website address.

RewriteRule ^(.*)$ http://www.yoursite.com/307.php [R=307,L]
The above includes comments for your convenience. To get the redirect up and running, rename your existing .htaccess file to live.htaccess then rename this one to .htaccess

Alternative Redirect 1: Meta Refresh

It's also possible to redirect traffic when visiting a page with the following line inside the head tag.
To do an immediate redirect:
<meta http-equiv="refresh" content="0; url=http://www.new-website.com" />
To redirect after 5 seconds:
<meta http-equiv="refresh" content="5; url=http://www.new-website.com" />

Alternative Redirect 2: PHP Header Redirect

You're able to redirect traffic by putting the following line at the very top of a php document (nothing can be above it).
          <?php
            header ('HTTP/1.1 301 Moved Permanently');
            header( "http://www.new-website.com" );
          ?>
        

WebSite URL