Successfully reported this slideshow.

10 Email Etc


Published on

Day 10 Email sending with php

Published in: Technology
  • Be the first to comment

  • Be the first to like this

10 Email Etc

  1. 1. PHP Day 10 Geshan Manandhar Developer, Young Innovations Private Limited
  2. 2. Email with PHP <ul><li><?php </li></ul><ul><li>$to = ''; </li></ul><ul><li>$subject = 'Test email'; </li></ul><ul><li>$message = &quot;Hello World! This is my first mail.&quot;; </li></ul><ul><li>//define the headers we want passed. Note that they are separated with </li></ul><ul><li>$headers = &quot;From: Reply-To:;; </li></ul><ul><li>//send the email </li></ul><ul><li>$mail_sent = mail( $to, $subject, $message, $headers ); </li></ul><ul><li>if($mail_sent){ </li></ul><ul><li>print &quot;Mail sent&quot;; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li>print &quot;Mail failed.&quot;; </li></ul><ul><li>} </li></ul><ul><li>?> </li></ul>
  3. 3. Use of Emails <ul><li>Emails are used as an alert system in database focused application. </li></ul><ul><li>It is sent to notify application user about various activities. </li></ul><ul><li>Applications like e-card system rely heavily on email. </li></ul><ul><li>Server configuration, no. or emails allowed etc are also vital in applications that use e-mail. </li></ul>
  4. 4. Back to basics <ul><li>Simple program to find a number is odd or even. </li></ul><ul><li><?php </li></ul><ul><li>$number = 4; </li></ul><ul><li>if($number%2){ </li></ul><ul><li>$odd = 1; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li>$odd = 0; </li></ul><ul><li>} </li></ul><ul><li>//contd… </li></ul>
  5. 5. Back to basics – C style printf <ul><li>if($odd){ </li></ul><ul><li>printf (&quot;%d is odd.&quot;, $number); </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li>printf (&quot;%d is even.&quot;, $number); </li></ul><ul><li>} </li></ul><ul><li>?> </li></ul>
  6. 6. Back to the basics - Ternary <ul><li>Ternary operator </li></ul><ul><li><?php </li></ul><ul><li>$number = 4; </li></ul><ul><li>$odd = ($number%2) ? 1 : 0; //ternary operator </li></ul><ul><li>// above single line is equivalent to 6 lines of code of previous program </li></ul><ul><li>if($odd){ </li></ul><ul><li>printf (&quot;%d is odd.&quot;, $number); </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li>printf (&quot;%d is even.&quot;, $number); </li></ul><ul><li>} </li></ul><ul><li>?> </li></ul>
  7. 7. Better programming mantras <ul><li>Use Ternary Operator to save time and LOC- Lines of code. </li></ul><ul><li>Utilize array and array related functions to the maximum. </li></ul><ul><li>Implement DRY in coding. </li></ul><ul><ul><li>Instead of creating multiple functions just add a parameter to existing function to do the job. </li></ul></ul><ul><li>Use debugging techniques </li></ul><ul><ul><li>Use functions like print, echo, print_r, var_dump at relevant breakpoints to check the value of the variable. </li></ul></ul>
  8. 8. If you have no web template <ul><li>If you layout looks too dull and you can’t design or don’t want to design. </li></ul><ul><li>Then try out these websites to get free web templates: </li></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li>More at </li></ul></ul>
  9. 9. Simply theme your code <ul><li>Download the template you want. </li></ul><ul><li>See the <div> structure. </li></ul><ul><li>Change the static content to the dynamic (PHP) content you want to replace with. </li></ul><ul><li>Check your output. </li></ul><ul><li>Hit and trail works if you are not good at designing. </li></ul>
  10. 10. A themed users table
  11. 11. Questions
  12. 12. To do <ul><li>Inject your code to a layout from above mentioned website. </li></ul><ul><li>Make your login system fully functional. </li></ul><ul><li>Review you code – implement the mantras. </li></ul><ul><li>Assign message to a variable $message as per login information supplied by user, using the ternary operator. </li></ul><ul><li>Upload your files to your newly created sub-domain at 000webhost, test them. </li></ul>