10 Email Etc

1,159 views

Published on

Day 10 Email sending with php

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,159
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

10 Email Etc

  1. 1. PHP Day 10 Geshan Manandhar Developer, Young Innovations Private Limited www.geshanmanandhar.com http://www.php.net http://www.mysql.com
  2. 2. Email with PHP <ul><li><?php </li></ul><ul><li>$to = 'someone@somemail.com'; </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: webmaster@example.com Reply-To: webmaster@example.com&quot;; </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>http://www.opendesigns.org/ </li></ul></ul><ul><ul><li>http://www.freecsstemplates.org/ </li></ul></ul><ul><ul><li>http://www.freewebsitetemplates.com/ </li></ul></ul><ul><ul><li>More at http://delicious.com/geshan/WebTemplates </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>

×