Archive for the ‘PHP’ Category

Day-1 (Part-1):

I am getting many requests from students and PHP Programmers for an easy CakePHP Tutorial with step by step demonstration. I also have searched various sources, but unfortunately, CakePHP itself  lacks demonstrations and also, the existing tutorials are outdated with CakePHP 1.2.  Here is a tutorial demonstrating a small Project with CakePHP 2.5.2. On every saturday/sunday, I am able to update the blog as getting very less time to do this.

1. Download cakephp from cakephp.org   version 2.5.2 (Stable)
2. Keep it at root (For me it is C://wamp/www/)
3. Create a folder “tut” with in “www” (let “tut” refers  “tutorial”)
4. Extract all files of CakePHP zip file to “tut” folder as shown below.
1

5. Now run the project. For me it is; localhost:81/tut
6. The page will display as below.
2
7. Open app/Config/core.php in any editor. (I am using Dreamweaver). Go to line number 225 and change the Security.salt to any alphanumeric string.  Now, go to Line Number 230 and change the Security.CipherSeed to any number as shown below.
Note: You can use this website to generate strong security salt.
3
8. Create a database “tut“. Again, I request you to use the naming convention as I am using. Once you do this project, you can manipulate and keep your research.

9. Rename app/config/database.php.default to database.php and open it in the editor.
4
5

10. Go to line number 65 and change the database-login id, database-password and database name. For me, it is like;
611. Now browse your project in the browser. For me, it is http://localhost:81/tut.  It will be like;
7
12. Now, We are ready to start our project.

You can comment if felt any difficulty in any step. You can comment in this post or can mail me at deb882003@gmail.com
I may take some to reply (with in 24 Hours), as per my busy schedules.

Day-1 (Part-2) >>

Advertisements

Using Swift Mailer

Posted: August 9, 2013 in PHP
Tags: ,

If you wish to use any alternative of mail() then you better go for Swift Mailer.

Download it here: http://swiftmailer.org/download

I like it because, the features like “Attachment” are quite simple here….

Sending a Normal Mail:

require_once 'lib/swift_required.php';

// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
  ->setUsername('your username')
  ->setPassword('your password')
  ;

/*
You could alternatively use a different transport such as Sendmail or Mail:

// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');

// Mail
$transport = Swift_MailTransport::newInstance();
*/

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
  ->setBody('Here is the message itself')
  ;

// Send the message
$result = $mailer->send($message);

Sending Mail with Attachment:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require_once 'lib/swift_required.php';

// Create the message
$message = Swift_Message::newInstance()

  // Give the message a subject
  ->setSubject('Your subject')

  // Set the From address with an associative array
  ->setFrom(array('john@doe.com' => 'John Doe'))

  // Set the To addresses with an associative array
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))

  // Give it a body
  ->setBody('Here is the message itself')

  // And optionally an alternative body
  ->addPart('<q>Here is the message itself</q>', 'text/html')

  // Optionally add any attachments
  ->attach(Swift_Attachment::fromPath('my-document.pdf'))
  ;