How to enable php mail() in your ubuntu

In my last post I showed you how you can set up an ubuntu server for apache, php, mysql, phpmyadmin and wordpress multiste. Below is the link if you want to take a look:

How to setup a VPS (Ubuntu) for WordPress hosting – A to Z tutorial

Today, we will learn how we can enable email in that server, so that we can use php mail() to send mail from our system. Today I won’t go in that detail but just to set a simple mail server.

The simplest way to enable mail in your ubuntu is to run the following command:

[html]
sudo apt-get install sendmail
[/html]

It will install a copy of sendmail that listens locally. If you install that, then php can use the built in mail() function. There also won’t be a risk of becoming a remote relay if you install like this as well. If you plan on sending mail out to other internet domains, you will need to make sure the IP address of the machine sending mail has a reverse DNS entry (PTR record) set up as well. Most large ISP’s will reject your mail if your IP does not have a PTR record or one that points to a generic host (e.g. 1.2.3.3.domain.isp.com). It should reverse to something like mail.yourdomain.com

In other case, also I prefer to use postfix. It is also easy to install. To install run this command:

[html]
sudo apt-get install postfix
[/html]

During the installation a dialogue box will be appeared where you need to select “Internet Site” and the next box give your domain name as system domain.

Now to make it fully functional, we need to edit configuration file. Open the configuration file:

[html]
sudo nano /etc/postfix/main.cf
[/html]

Make the following changes:

[html]
myhostname = yourdomain.com
virtual_alias_maps = hash:/etc/postfix/virtual (you need to replace the line which has alias_maps)
mydestination = localdomain, localhost, localhost.localdomain, localhost, yourdomain.com
relayhost = (can be blank by default)
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
[/html]
Press ‘cntrl x’ to exit the file and then ‘Y’ to save the file.

Reload the configuration:

[html]
sudo /etc/init.d/postfix reload
[/html]

Also, you can add users to the alias file. Open up the the alias database:

[html]
sudo nano /etc/postfix/virtual
[/html]

Enter the names and emails of the user like:

[html]
system@domain.com user1
support@example.com user2
[/html]
Press ‘cntrl x’ to exit the file and then ‘Y’ to save the file.

Once you are finished, save, exit, and run the following command to enable:

[html]
postmap /etc/postfix/virtual
[/html]

Again restart the postfix:

[html]
sudo /etc/init.d/postfix reload
[/html]

Now we need to test. Create a file in your server root, called – mail.php, for example. Add the following code:

[php]
<?php
$headers = ‘From: yourmail@gmail.com’ . “rn” .
‘Reply-To: yourmail@gmail.com’ . “rn” .
‘X-Mailer: PHP/’ . phpversion();
if(mail(“targetMail@gmail.com”, “Test Email”, “Email is set up”, $headers)) echo “Correct”;
else echo “Wrong”;
[/php]

And run the file by yourdomain.com/mail.php

If it prints “Correct”, then email is setup and check the inbox :)

You also can try sending email from your terminal. Run the following command:

[html]
sendmail targetMail@domain.com
[/html]

Then write the email contents and press Ctrl + D to send email.

Now, play with emails in your server :)

post

How to hide a plugin for non-admin users in wordpress

Today I will show how you can hide a plugin from the users that are non-admin. If you use a multisite, you can control a lots of stuffs with Pro Sites plugin. But what if you don’t want to use Pro Sites?

This simple scripts will do the job for you.

[php]

function custom_plugins( $plugins ){

if ( !is_super_admin() ) {
// Add comma separated paths of plugins that you want to hide
$hide_plugins = array(‘pluginFolder/pluginFile.php’, ‘pluginFile.php’);
foreach ($hide_plugins as $hide_plugin) {
unset($plugins[$hide_plugin]);
}
}
return $plugins;
}
add_filter(‘all_plugins’, ‘custom_plugins’);
[/php]

You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name ‘mu-plugins’. If there is no folder in that name, then create a folder, name it ‘mu-plugins’, create a file inside that, give any name you like and paste the code in there. You don’t need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag <?php at the beginning of the code.

I have shown option for both – 1. if the plugin file is inside a folder 2. if the plugin file is in plugin root folder.

Just add more items in the array to hide :)

post

How to redirect user to his primary blog on login in a multisite

Some web admins don’t like to to redirect the user to network site dashboard upon login. So, they want to redirect the user to the primary blog’s dashboard. Well, it’s fair enough.

So, if an user 5 subsites, and when he will login, he will be redirected to his primary blog’s dashboard. He will still be able to access all of his sites from My Sites link at the top left of admin bar. He is also able to change his primary blog.

So the following script will do the job:
[php]
function go_to_primary_blog($redirect_to, $request, $user){
$user_info = get_userdata($user->ID);
return get_blogaddress_by_id($user_info->primary_blog) . ‘wp-admin’;
}
add_filter(“login_redirect”, “go_to_primary_blog”, 10, 3);
[/php]

You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name ‘mu-plugins’. If there is no folder in that name, then create a folder, name it ‘mu-plugins’, create a file inside that, give any name you like and paste the code in there. You don’t need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag <?php at the beginning of the code.

Hope it helps!

post

How to setup a VPS (Ubuntu) for WordPress hosting – A to Z tutorial

VPS is being more popular day by day. Personally I prefer to use DigitalOcean, they are cheap and their support is awesome. They also have tons of tutorial guides, chat community. Also they answer your questions very quickly in their support forum.

Let’s dive into the main point. When you will have a VPS droplet, you will get an IP, login username, password that you can use to login in your VPS via command line. There are several tools like Putty in windows, but I love to work in command line in Linux or Mac OS.

Let’s assume the IP is 111.111.111.111 where username is root and password is myvps. So, now connect to the VPS using terminal:
[html]
ssh root@111.111.111.111
[/html]
If you connect for the first time, the following message could be appeared:
[box type=”shadow”]The authenticity of host ‘111.111.111.111 (111.111.111.111)’ can’t be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)?[/box]
Just type yes and press enter. It will ask for password, give the password myvps and press enter, you’re in!

Note that, if you have connected to same VPS using other IP before, then you may see a error message like the following:
[box type=”shadow”]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Please contact your system administrator.
Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
Offending key in /home/user/.ssh/known_hosts:1
RSA host key for ras.mydomain.com has changed and you have requested strict checking.
Host key verification failed.[/box]
Then you need to run these commands in terminal, before connecting to VPS:
[html]
$ ssh-keygen -R 111.111.111.111
[/html]

Now we will add new user for your server, as we won’t use root user. “root” users is only for administrative purpose. Let’s create a new user:
[html]
sudo adduser sandbox
[/html]
Now a user having username as ‘sandbox’ will be created, but you are not done yet. You will be asked for password immediately. Give password and press enter. Now the system will ask for additional details like name, email etc. You don’t need to provide those information if you don’t want to, just keep pressing enter until you see the following message:
[box type=”shadow”]
Is the information correct? [Y/n]
[/box]
Press Y and then press enter. New user ‘sandbox’ with password (in my case it’s sandbox too) is created!

Now we need to give root privileges to sandbox user:
[html]
sudo /usr/sbin/visudo
[/html]
A text file will be opened in the terminal, add the following lines:
[html]
root ALL=(ALL:ALL) ALL
sandbox ALL=(ALL:ALL) ALL
[/html]
Press ‘cntrl x’ to exit the file and then ‘Y’ to save the file.

[box type=”shadow”]
If you want to delete any user from your system, use the following command:
[html]
sudo userdel sandbox
[/html]
And then you need to delete the user’s home directory:
[html]
sudo rm -rf /home/sandbox
[/html]
To change user:
[html]
su sandbox
[/html]
[/box]

post

WordPress Meet The Team Plugin – best ever

Meet the Team is a WordPress plugin that allows you to easily create and manage teams. You can display single teams as multiple columns, you can also showcase all teams as a filterable isotope gallery, easy social links management included.

The purpose of this plugin is to allow you to create a “Meet the Team/Partners” page for a website. This plugin makes it easy to create a Team Page to showcase your most important assets.

[purchase_link id=”633″ text=”Add to Cart” style=”button” color=”green”]

It’s very cheap and easy to use. You can check the “demo” and “how to use” in following video.

Special thanks to MixItUp.

How to use?

Just like adding a new post or page.

Use shortcoe [my-team] to show whole team or [my-team cat=”CAT_ID”] to show a specific category. You will also have a widget to show a member like Highlight or Spotlight.

If ANY question, please feel free to drop an email with your purchase code at aknath.707@gmail.com

Total Sales: 149

Check Screenshots:

Screen Shot 2013-08-02 at 4.22.05 AM

Meet the team Meet the team

80X80

8

7

6

4

3

2

1

So, why wait?