Personal Project

Showing posts with label Html5. Show all posts
Showing posts with label Html5. Show all posts

Wednesday, March 2, 2016

Send Email in PHP with Japanese subject and body


   Before, we get started, you must have an SMTP server that can receive the emails from your machines 

   and send them to the recipient

    (i.e. your corporate exchange or Gmail).

 

    How to Setup Email on Linux Using Gmail and SMTP

  • Install ssmtp 

    sudo apt-get install ssmtp

    Edit ssmtp file

    sudo vim /etc/ssmtp/ssmtp.conf
  • root=username@gmail.com
    mailhub=smtp.gmail.com:465
    rewriteDomain=gmail.com
    AuthUser=username@gmail.com
    AuthPass=password
    FromLineOverride=YES
    UseTLS=YES

In order to make the default (root) “from” field be the server name, edit the/etc/ssmtp/revaliases file:
sudo vim /etc/ssmtp/revaliases
And add into it the desired translation which in our Gmail examples case will be:
root:username@gmail.com:smtp.gmail.com:465
Incredibly this is all you have to do to enable the ability. From now on, the machine will Email you when something is up.

Test Email Command

Lets test that our ssmtp setup was correct by sending an Email:

echo "Test message from Linux server using ssmtp" | sudo ssmtp -vvv your-email@some-domain.com

 

 

Use the following codes to send email with PHP

 

 

    //  $to  : receiver email address
    //  $subject :  Japanese subject
    //  $message : Japanese body
    function sendEmail($to, $subject, $message)
    {
        if(!isset($to) || !isset($subject) || !isset($message)) {
            return;
        }
   
         // Set up environment
        mb_language('Japanese');
        mb_internal_encoding('UTF-8');
   
        // Set up subject
        $headers ='From: '.mb_encode_mimeheader("ありがとうございます").' <test@123.jp>' . "\r\n";
                'Reply-To: test@123.jp' . "\r\n" .
                    'X-Mailer: PHP/' . phpversion();
   
          // Set up body
        $message = mb_convert_encoding($message, "JIS", "UTF-8");
       
         //  Send email  
        if(mb_send_mail($to, $subject, $message, $headers))
        {
                error_log("#### Send mail OK ####");
   
        }else {
                 error_log("#### Send mail Error ####");
      }
       
    } // End Send Email

 




Create a dropdown Date using JavaScript

1. Include jquery, moment.js and combodate.js on your page
  1. <script src="js/jquery.js"></script>
  2. <script src="js/moment.min.js"></script>
  3. <script src="js/combodate.js"></script>
2. Markup input elements to be used for date and time values
  1. <input name="playerDate" value="15-05-1984" data-format="DD-MM-YYYY" data-template="D MMM YYYY">  
3.Markup Javascript
 <script type="text/javascript">
  // Date 
  $(function(){
   $('#playerDate').combodate();  });
</script> 

 
Download source code: 
https://github.com/gcoolmaneric/jquery-php-html5/tree/master/dropdownDate

 

Upload images using JQuery and PHP for different device

Do you want to create a form that could allow you to upload images on different device ?
You can use jquery and php to make it done.

Add the following codes to html page. 

<body>
     <form id="upload" method="post" action="upload.php" enctype="multipart/form-data">
            <div id="drop">
                Drop Here

                <a>Browse</a>
                <input type="file" name="upl" multiple />
            </div>

            <ul>
                <!-- The file uploads will be shown here -->
            </ul>

        </form>

        <!-- JavaScript Includes -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script src="assets/js/jquery.knob.js"></script>

        <!-- jQuery File Upload Dependencies -->
        <script src="assets/js/jquery.ui.widget.js"></script>
        <script src="assets/js/jquery.iframe-transport.js"></script>
        <script src="assets/js/jquery.fileupload.js"></script>
       
        <!-- Our main JS file -->
        <script src="assets/js/script.js"></script>
</body>

PHP Code

upload.php
<?php

// A list of permitted file extensions
$allowed = array('png', 'jpg', 'gif','zip');

if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){

    $extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);

    if(!in_array(strtolower($extension), $allowed)){
        echo '{"status":"error"}';
        exit;
    }

    if(move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/'.$_FILES['upl']['name'])){
        echo '{"status":"success"}';
        exit;
    }
}

echo '{"status":"error"}';
exit;

?>

Download source codes:
https://github.com/gcoolmaneric/jquery-php-html5/tree/master/uploadImage


Change the maximum upload file size


You need to set the value of upload_max_filesize and post_max_size in your php.ini :
 vim /etc/php5/apache2/php.ini 
; Maximum allowed size for uploaded files.
upload_max_filesize = 20M

; Must be greater than or equal to upload_max_filesize
post_max_size = 20M