Category Archives: Php

Javascript number input field only and does not accept negative and string value

Html input field which will take only number input and will not accept negative number and string input. It will accept only numeric value.

Example:

<input id=”myNumber” type=”number” name=”my_number”  min=”0″ oninput=”this.value = (isNaN(Math.abs(this.value)))?0:Math.abs(this.value)”>

Above example will not take any negative number input and string input. It will accept only positive number.

PHP+Ubuntu Send email using gmail form localhost

https://stackoverflow.com/questions/33969783/phpubuntu-send-email-using-gmail-form-localhost

 

Please do following steps to send mail from localhost on Ubuntu/Linux through gmail :-

For that you need to install msmtp on Linux/Ubuntu server.

Gmail uses https:// (it’s hyper text secure) so you need install ca-certificates

~$ sudo apt-get install msmtp ca-certificates
It will take few seconds to install msmtp package.

Now you have to create configuration file(msmtprc) using , gedit editor.

~$ sudo gedit /etc/msmtprc
Now you have to copy and paste following code in gedit (file you created with above command)

defaults
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

account default
host smtp.gmail.com
port 587
auth on
user MY_GMAIL_ID@gmail.com
password MY_GMAIL_PASSSWORD
from MY_GMAIL_ID@gmail.com
logfile /var/log/msmtp.log
Don’t forget to replace MY_GMAIL_ID with your “gmail id” and MY_GMAIL_PASSSWORD with your “gmail password” in above lines of code.

Now create msmtp.log as

~$ sudo touch /var/log/msmtp.log

You have to make this file readable by anyone with

~$ sudo chmod 0644 /etc/msmtprc

Now Enable sendmail log file as writable with

~$ sudo chmod 0777 /var/log/msmtp.log

Your configuration for gmail’s SMTP is now ready. Now send one test email as

~$ echo -e “Subject: Test Mail\r\n\r\nThis is my first test email.” |msmtp –debug –from=default -t

MY_GMAIL_ID@gmail.com
Please check your Gmail inbox.

Now if you want to send email with php from localhost please follow below instructions:-

Open and edit php.ini file

~$ sudo gedit /etc/php/7.0/apache2/php.ini
You have to set sendmail_path in your php.ini file.

Check your SMTP path with

~$ which msmtp
and you will get /usr/bin/msmtp like that.

Search sendmail_path in php.ini and edit as below

; For Unix only. You may supply arguments as well (default: “sendmail -t -i”).
; http://php.net/sendmail-path
sendmail_path = /usr/bin/msmtp -t
Please check 3rd line carefully there is no semicolon before sendmail_path.

Now save and exit from gedit. Now it’s time to restart your apache

~$ sudo /etc/init.d/apache2 restart
Now create one php file with mail function from http://in2.php.net/manual/en/function.mail.php.

Do test and enjoy !!