Friday, 8 July 2016

Between PHP mailer() and the PHP’s mail() Function: The Case of Bulk Mailing for Corporate and Private Messaging



Is PHP mailer() an alternative to PHP’s mail() function?
In most cases, it’s an alternative to PHP’s mail() function, but there are many other cases where the mail() function is simply not flexible enough to achieve what you need.
First of all, PHPMailer provides an object oriented interface, whereas mail() is not object oriented. PHP developers generally hate to create $headers strings while sending emails using the mail() function because they require a lot of escaping – PHPMailer makes this a breeze. Developers also need to write dirty code (escaping characters, encoding and formatting) to send attachments and HTML based emails when using the mail() function whereas PHPMailer makes this painless.
Also, the mail() function requires a local mail server to send out emails. PHPMailer can use a non-local mail server (SMTP) if you have authentication.
Further advantages include:
  1. It can print various kinds of errors messages in more than 40 languages when it fails to send an email.
  2. Integrated SMTP protocol support and authentication over SSL and TLS.
  3. Can send alternative plaintext version of email for non-HTML email clients.
  4. Very active developer community which keeps it secure and up to date.
PHPMailer is also used by popular PHP content management systems like WordPress, Drupal, Joomla etc.
2.    Installing PHPMailer
You can install PHPMailer using Composer:
Composer require phpmailer/phpmailer.


3.    Sending Email from Local Web Server using PHPMailer
Here is the simplest example of sending an email from a local web server using PHPMailer
<?php
require_once "vendor/autoload.php";
//PHPMailer Object
$mail = new PHPMailer;
//From email address and name
$mail->From = "from@yourdomain.com";
$mail->FromName = "Full Name";
//To address and name
$mail->addAddress("recepient1@example.com", "Recepient Name");
$mail->addAddress("recepient1@example.com"); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("reply@yourdomain.com", "Reply");
//CC and BCC
$mail->addCC("cc@example.com");
$mail->addBCC("bcc@example.com");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
    echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
    echo "Message has been sent successfully";
}
The code and comments should be sufficiently clear to explain everything that’s going on.
4.    Sending an E-Mail with Attachments
Let’s see an example on how to send an email with attachments using PHPMailer.
<?php
require_once "vendor/autoload.php";
$mail = new PHPMailer;
$mail->From = "from@yourdomain.com";
$mail->FromName = "Full Name";
$mail->addAddress("recipient1@example.com", "Recipient Name");
//Provide file path and name of the attachments
$mail->addAttachment("file.txt", "File.txt");       
$mail->addAttachment("images/profile.png"); //Filename is optional
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
    echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
    echo "Message has been sent successfully";
}
Here we are attaching two files i.e., file.txt which resides in the same directory as the script and images/profile.png which resides in images directory of the script directory.
To add attachments to the email we just need to call the function addAttachment of the PHPMailer object by passing the file path as argument. For attaching multiple files we need to call it multiple times.

5.    Using SMTP
You can use the mail server of another host to send email, but for this you first need to have authentication. For example: to send an email from Gmail’s mail server you need to have a Gmail account.
SMTP is a protocol used by mail clients to send an email send request to a mail server. Once the mail server verifies the email it sends it to the destination mail server.
Here is an example of sending an email from Gmail’s mail server from your domain. You don’t need a local mail server to run the code. We will be using the SMTP protocol:
<?php
require_once "vendor/autoload.php";
$mail = new PHPMailer;
//Enable SMTP debugging.
$mail->SMTPDebug = 3;                              
//Set PHPMailer to use SMTP.
$mail->isSMTP();           
//Set SMTP host name                         
$mail->Host = "smtp.gmail.com";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;                         
//Provide username and password    
$mail->Username = "name@gmail.com";                 
$mail->Password = "super_secret_password";                          
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "tls";                          
//Set TCP port to connect to
$mail->Port = 587;
$mail->From = "name@gmail.com";
$mail->FromName = "Full Name";
$mail->addAddress("name@example.com", "Recepient Name");
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
    echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
    echo "Message has been sent successfully";
}
Gmail requires TLS encryption over SMTP so we set it accordingly. Before you send via SMTP, you need to find out the host name, port number, encryption type if required and if authentication is required you also need the username and password. Note that having a two-factor authentication enabled on Gmail won’t let you use their SMTP with username/password – instead, additional configuration will be required.
One big advantage in using remote SMTP over local mail is that if you use PHP’s mail() function to send email with the from address domain set to anything other than the local domain name (name of the server), then the recipient’s email server’s attack filters will mark it as spam. For example, if you send an email from a server with actual host name example.com with the from address name@gmail.com to name@yahoo.com, then Yahoo’s servers will mark it as spam or display a message to the user not to trust the email because the mail’s origin is example.com and yet it presents itself as if coming from gmail.com. Although you own name@gmail.com, there is no way for Yahoo to find that out.


6.    Retrieving E-Mails using POP3
PHPMailer also allows POP-before-SMTP verification to send emails. In other words, you can authenticate using POP and send email using SMTP. Sadly, PHPMailer doesn’t support retrieving emails from mail servers using the POP3 protocol. It’s limited to only sending emails.
7.    Displaying Localized Error Messages
$mail->ErrorInfo can return error messages in 43 different languages.
To display error messages in a different language, copy the language directory from PHPMailer’s source code to the project directory.
To return error messages in, for example, Russian, set the PHPMailer object to the Russian language using the below method call:
$mail->setLanguage("ru");
You can also add your own language files to the language directory.
Conclusion
If you are a PHP developer, there is little chance of avoiding having to send emails programmatically. While you may opt for third party services like Mandrill or Sendgrid, sometimes that just isn’t an option, and rolling your own email sending library even less so. That’s where PHPMailer and its alternatives (Zend Mail, Swiftmailer, etc.) come in.
Image Source: https://i.ytimg.com/vi/pdiO1ayo2TQ/maxresdefault.jpg

Thursday, 10 March 2016

You might not have noticed this about your keyboard, or maybe you have just always wondered what those two little bumps on the F and J keys are. They actually weren’t invented until 2002, but now almost every keyboard made includes the little things. If you place both your index fingers in on their respective f and j keys, you might notice something: your hands are perfectly positioned to reach every key on the keyboard. In an effort to improve the speed of many typists, and create a keyboard that can be used without looking, the bumps were added.

For those of you that still type with the two finger approach at a breakneck speed of two words per minute, the little bumps may not be of too much help. However, if you’re looking to start typing fast and keep yourself from having to look at the keyboard, try using the bumps to help you figure out where each letter key is.

In the “touch typing” realm, when your index fingers are placed on the bumps and the other fingers placed on the keys beside them, this is called “home row.” Home row is where your fingers should come back to a natural resting position when finished typing. There are many websites out there that can help you improve your typing speed. Maybe you could even reach over 100 words per minute!

Invented by June E. Botich, the small little bumps help many around the world type just a little bit faster. Try to start practicing your typing using the bumps and see how much faster you can finish all those papers you have to write. Who knew those little bumps on F and J could be so useful?

Sunday, 27 December 2015

How To Remove Short-Cut Virus From Your PC Using Windows CMD (Command Prompt)

First and foremost, it's advisable you update your Anti-virus to see how it all goes and if this doesn't solve the issue, you can proceed to the methods below. Apart from updating your Antivirus,there are some softwares capable of getting rid of this virus. The best of them are listed below;

1. SVRTool.exe

2. Autorun Exterminator

3. Smadav shortcut virus remover

4. Wnload Combofix shortcut remover

So, download any of those and follow the instructions on the sites to use them.

1. Manual fixes are also available to solve this problem.Therefore,you can make use of any method you consider easier.

a). Insert whichever drive is infected by this virus into your system and check the drive's extension i.e. A: .... Z: from ‘My Computer’,

b). Click on Start » Run / Winkey+R and type cmd in the textbox provided - Hit Enter.

c). Copy paste the code below into the command prompt and hit 'Enter'.
         attrib -h -r -s /s /d E:\*.*

PLEASE NOTE THAT; You will have to change E: to your drive's extension.)

d). Now,check to confirm that the virus has been completely cleared-off. Else, you can use this alternative outlined below.

a). Go to the control panel to untick “Hide protected operating system files” or simply use the search box.

b.)Navigate to “C:\Windows\System32” and manually delete regsvr

c.)If you can't find the file in System32, then try locating it in “C:\program files”. If you still cannot find it there,then try locating it in the “Processes” tab in Task Manager.

Now, with all the software & manual fixes highlighted above,one is bound to work for the drive.

Friday, 25 December 2015

How To Password Protect Your USB Flash Drive

Everyone now a days has one or two additional USB flash drives and hard disks with them because USB flash drives makes sharing of data very easy and fast. You can share large files very easily because downloading the same file from the internet would take a very long time and also utilize our data. So instead, we prefer to take that file from a friend who has that file. We can share very heavy files using USB flash drives because now you can even buy a USB flash drive with a storage capacity of 512 GB.
Not only sharing of Movies and videos, some people even share very personal data using pendrive. What if the pendrive gets lost somewhere. Is the data still Safe? Can someone else access that file except me? Of course, if you have not set a password on your USB flash drive.
Here’s how to protect your USB flash drive with a password without any software.
Just follow the steps outlined below to set a password on your USB flash drive.
Step 1:- Insert the USB flash drive which you want to protect in your Computer.
Step 2:-  Open My computer.
Step 3:- Right click on your USB flash drive and click on Turn on BitLocker.
Step 4:- Now enter the password which you want to set.
Step 5:- Click next. Now it will give you some alternative methods by which you can recover back your USB flash drive if you forgot your password. Then you can use this file as a password.
Step 6:- Save that file to your computer and again click next.
NOTE: Copy the encrypted file into several locations (most reliably cloud drives) should in case you forget your password so you can easily use it to recover your password when you have forgotten it because without this, you cannot decrypt the USB flash drive when you forget your password.

Thursday, 24 December 2015

Merry Xmas To All Afrikan Children.

Are You No More Different From The Government of Today's World? Prove It! Go Look For A Homeless, Displaced, Orphaned etc. Afrikan Child and Put A Smile on His/Her Face Today As A Mark of Celebration of the Xmas Festivity.
Merry Xmas... To All The Homeless, Displaced, Orphaned, Abandoned, Malnourished etc. Children Out There. May Someone Make This Xmas Worthwhile for You All as We Celebrate The Season.

Wednesday, 16 December 2015

Between the COAS and the Shiite's: What Yardstick for Boundary.

It's high time we defined where and what our boundaries and limits as a body, bodies, group or groups are in the country of ours. It is very obvious that people and organizations or groups have begun to violate public order and peace all under the excuse of human rights and protests. The recent protest and confrontation between the team of escort and the Shiites at Zaria, Kaduna is an example of such violations and this calls for a proper definition of "boundaries" to the citizens and people of Nigeria. On watching the video and other videos of the incident on YouTube and other news channels one will shocked to discover that the team of soldiers and the COAS are in NO WAY wrong to have metted such action on the group following the way the Generals and his soldiers pleaded with the protesters that they "the Army" are just passing through and should be allowed to go for their duty. Lest you forgot, these soldiers have sworn with their lives to defend the sovereignty and integrity of this nation and as such, were on a trip to go discuss one or two of such measures they will be employing in protecting our nation when these group of protesters, the Shiites, barricaded the road. I watched in dismay, the total disregard of human rights and peace and order by this group as they were being pleaded with by the General and his team for up to 15mins only to have this group delay and violate their right to passage and freedom of movement (of the soldiers). One begins to wonder if these people actually believe the "soldiers" and our "military" in general don't have their rights as humans or if they (the Shiites) believe they have higher rights than the soldiers. This issue should not be politicized to favour any region, group or what have you in any part of this country, whatsoever, in anyway for it will only escalate the menace. Like I saw somewhere on one social network community "I have never seen in any movie where soldiers are begin civilians to allow them (the soldiers) exercise their rightful given human rights" yet, these soldiers spent more than twenty minutes begging and pleading with these Shiites to allow them through to their function. Also, the Iranians protesting should be termed enemies of democracy because this video proves that the Shiites is just another time bomb of insurgency waiting to explode. Enough is too much, no group(s) holds more rights than any individual or group(s) in the world over so, they should be held responsible for manslaughter. Not the COAS or the Army. Let's call a spade a spade and fix the round peg in a round hole.

Watch Video Here