PHP Script To Send Email Using SMTP

It’s very easy to send email using PHP via SMTP, first of all you must downloads PHP Mailer (https://github.com/PHPMailer/PHPMailer), after we will use small script as an example which will connect to smtp and send email.

<?php
 
require_once "PHPMailer-master/PHPMailerAutoload.php";
 
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mail.domain.com";
$mail->SMTPAuth = true;
$mail->Username = "username";
$mail->Password = "password";
$mail->From = "[email protected]";
$mail->FromName = "Your Name";
$mail->AddAddress("[email protected]");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "This is subject";
$mail->Body = "THis is body <b>html</b>";
$mail->AltBody = "This is the body in plain text.";
if (!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

Beautify XML to print in C#

You can print XML normally but it will not be formatted, we have solution which can help you to output XML in nice format We will use XmlTextWriter function to do this here is simple function which you can use in project.

public static String BeutyXML(String XML)
        {
            String Result = "";
 
            MemoryStream mStream = new MemoryStream();
            XmlTextWriter writer = new XmlTextWriter(mStream, Encoding.Unicode);
            XmlDocument document = new XmlDocument();
 
            try
            {                
                document.LoadXml(XML);
                writer.Formatting = Formatting.Indented;
 
                document.WriteContentTo(writer);
                writer.Flush();
                mStream.Flush();
 
                mStream.Position = 0;
 
                StreamReader sReader = new StreamReader(mStream);
                String FormattedXML = sReader.ReadToEnd();
 
                Result = FormattedXML;
            }
            catch (XmlException)
            {
            }
 
            mStream.Close();
            writer.Close();
            
            // Return formatted XML
            return Result;
        }

you can call it with simple command

textBox2.Text = BeutyXML(payout.Getsoapresponse());

That’s all!

Simple Code To Read CSV file – JAVA

it’s very simple to read CSV and then get all information by columns this is simple code which will help you with it

try {
BufferedReader br = new BufferedReader(new FileReader("./customer-list.csv"));
  while ((line = br.readLine()) != null) {
   if (!line.isEmpty()) {
    // use comma as separator
    String[] data = line.split(",");
    //data[0] contains first column if you want second one use data[1] and so on
    System.out.println(data[0]);
}
}
 
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

Skip First line with FileReader – Java

Example how to skip first line of any file which you want to read using FileReader in Java

        BufferedReader br = new BufferedReader(new FileReader("./test.csv"));
 
        br.readLine();
        while ((line = br.readLine()) != null) {
            if (!line.isEmpty()) {
                // use comma as separator
                String[] data = line.split(",");
            }
        }

all what we are doing is adding br.readLine(); before while loop this will read first line so it will be skipped in loop.

MySQL fetching the first row instead of all

This problem normally occurs when your forgetting to place array into container, for example PHP

$query = mysql_query( "SELECT * FROM `table`" );
$getrows = mysql_fetch_assoc( $query );
 
foreach ( $getrows as $row ) {
echo $row['id'];
}

We will have in this situation only first row not others, to get all rows we must use while() loop PHP

$query = $db->query( "SELECT * FROM `matches`" );
while ( $rows = mysql_fetch_array( $query ) ) {
echo rows['id'];
}

using while loop your getting all rows you can save them into array and so on.

Install nginx + varnish + apache in Cpanel/WHM

By default Cpanel comes with apache only, if you need to install Nginx,Varnish to make faster service you can use several plugins, I will start with free one and then tell about shareware.

ApacheBooster

Plugin comes with already configured Nginx and Varnish, to install and use terminal

wget http://prajith.in/downloads/apachebooster.tar.gz
tar -zxf apachebooster.tar.gz
cd apachebooster
bash install.sh  or sh install.sh

after installation you will see apachebooster in WHM plugins

You can configure Varnish and Nginx from here, and also purge varnish cache if needed. I think this plugin have have all what is needed but if your searching for more you can buy Cpanel plugin from Unixy, I think they have same functions but anyway it up to you which one to choose.

Apache, Mysql, PHP, Vernish, Webmin on Debian-Ubuntu

Most of all servers come with installed apache,php and mysql but but without vernish and webmin we need to install this soft manually on Debian or ubuntu.

We will start to upgrade out system:

apt-get update
apt-get dist-upgrade

Now if apache is not installed we should install it:

apt-get install apache2

install mysql server:

apt-get install mysql-server

install PHP:

apt-get install php5 php-pear php5-mysql php5-common php5-mcrypt php5-curl php5-cli php5-gd php5-dev

install curl(is needed for vernish) and unzip(if not installed):

apt-get install curl unzip

Now we must install dependencies for webmin control panel:

apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python

Wget webmin and install it:

wget http://prdownloads.sourceforge.net/webadmin/webmin_1.660_all.deb
dpkg –install webmin_1.660_all.deb

at least install vernish:

curl http://repo.varnish-cache.org/debian/GPG-key.txt | apt-key add –
echo “deb http://repo.varnish-cache.org/debian/ wheezy varnish-3.0” >> /etc/apt/sources.list
apt-get update
apt-get install varnish

Now all software installed you can access your webmin control panel using https://yourip:10000

Install Nginx, PHP, Mysql – Debian

Nginix is great web server it’s much faster then apache server, but we need to make some tasks to install and configure Nginix with PHP.

1) Install mysql server and other tools which we need

apt-get install gcc libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev openssl libxml2-dev libevent-dev mysql-client mysql-server

2) Normally debian already includes Nginix

apt-get update

apt-get install nginx

3) Now we can install PHP and extensions

apt-get update

apt-get install php5 php5-fpm php-pear php5-common php5-mcrypt php5-mysql php5-curl php5-cli php5-gd php5-dev

4) Start all services

service nginx start

service php5-fpm start

service mysql start

5) Start php,mysql,nginx at start

update-rc.d nginx default

update-rc.d mysql defaults

update-rc.d php5-fpm defaults

There was a problem creating the parked domain – Cpanel

There was a problem creating the parked domain. Show Details

Error from park wrapper: Using nameservers with the following IPs: xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx Sorry, the domain is already pointed to an IP address that does not appear to use DNS servers associated with this server. Please transfer the domain to this servers nameservers or have your administrator add one of its nameservers to /etc/ips.remotedns and make the proper A entries on that remote nameserver.

FIX :

If you have access to WHM you must make this change –

WHM > Tweak Settings > Domains > Allow Remote Domains > On