12
GeshanManandhar.com GeshanManandhar.com 1 PHP Day 10 PHP Day 10 Geshan Manandhar Geshan Manandhar Developer, Developer, Young Innovations Private Young Innovations Private Limited Limited www.geshanmanandhar.com www.geshanmanandhar.com http://www.php.net http://www.mysql.com

10 Email Etc

Embed Size (px)

DESCRIPTION

Day 10 Email sending with php

Citation preview

Page 1: 10 Email Etc

GeshanManandhar.comGeshanManandhar.com 11

PHP Day 10PHP Day 10

Geshan ManandharGeshan ManandharDeveloper,Developer,

Young Innovations Private LimitedYoung Innovations Private Limitedwww.geshanmanandhar.comwww.geshanmanandhar.com

http://www.php.net http://www.mysql.com

Page 2: 10 Email Etc

GeshanManandhar.com 2

Email with PHPEmail with PHP<?php<?php$to = '[email protected]';$to = '[email protected]';$subject = 'Test email';$subject = 'Test email';$message = "Hello World!\n\nThis is my first mail.";$message = "Hello World!\n\nThis is my first mail.";//define the headers we want passed. Note that they are separated with \r\n//define the headers we want passed. Note that they are separated with \r\n$headers = "From: [email protected]\r\nReply-To: $headers = "From: [email protected]\r\nReply-To:

[email protected]";[email protected]";//send the email//send the email$mail_sent = mail( $to, $subject, $message, $headers );$mail_sent = mail( $to, $subject, $message, $headers );if($mail_sent){if($mail_sent){

print "Mail sent";print "Mail sent";}}else {else {

print "Mail failed.";print "Mail failed.";}}

?>?>

Page 3: 10 Email Etc

GeshanManandhar.com 3

Use of EmailsUse of Emails

►Emails are used as an alert system in Emails are used as an alert system in database focused application.database focused application.

► It is sent to notify application user It is sent to notify application user about various activities.about various activities.

►Applications like e-card system rely Applications like e-card system rely heavily on email.heavily on email.

►Server configuration, no. or emails Server configuration, no. or emails allowed etc are also vital in allowed etc are also vital in applications that use e-mail.applications that use e-mail.

Page 4: 10 Email Etc

GeshanManandhar.com 4

Back to basicsBack to basics

► Simple program to find a number is odd or Simple program to find a number is odd or even.even.

<?php<?php$number = 4;$number = 4;

if($number%2){if($number%2){$odd = 1;$odd = 1;

}}else {else {

$odd = 0;$odd = 0;}}

//contd…//contd…

Page 5: 10 Email Etc

GeshanManandhar.com 5

Back to basics – C style printfBack to basics – C style printf

if($odd){if($odd){

printf ("%d is odd.", $number);printf ("%d is odd.", $number);

}}

else {else {

printf ("%d is even.", $number);printf ("%d is even.", $number);

}}

?>?>

Page 6: 10 Email Etc

GeshanManandhar.com 6

Back to the basics - TernaryBack to the basics - Ternary

► Ternary operatorTernary operator<?php<?php$number = 4;$number = 4;$odd = ($number%2) ? 1 : 0; //ternary operator$odd = ($number%2) ? 1 : 0; //ternary operator////above single line is equivalent to 6 lines of code of previous above single line is equivalent to 6 lines of code of previous

programprogram

if($odd){if($odd){printf ("%d is odd.", $number);printf ("%d is odd.", $number);

}}else {else {

printf ("%d is even.", $number);printf ("%d is even.", $number);}}

?>?>

Page 7: 10 Email Etc

GeshanManandhar.com 7

Better programming mantrasBetter programming mantras

► Use Use TernaryTernary Operator to save time and LOC- Operator to save time and LOC- Lines of code.Lines of code.

► Utilize Utilize arrayarray and array related functions to and array related functions to the maximum.the maximum.

► Implement DRY in coding. Implement DRY in coding. Instead of creating multiple functions just Instead of creating multiple functions just add a add a

parameterparameter to existing function to do the job. to existing function to do the job.► Use Use debuggingdebugging techniques techniques

Use functions like print, echo, print_r, var_dump Use functions like print, echo, print_r, var_dump at relevant breakpoints to check the value of the at relevant breakpoints to check the value of the variable.variable.

Page 8: 10 Email Etc

GeshanManandhar.com 8

If you have no web templateIf you have no web template

► If you layout looks too dull and you If you layout looks too dull and you can’t design or don’t want to design.can’t design or don’t want to design.

►Then try out these websites to get free Then try out these websites to get free web templates:web templates: http://www.opendesigns.org/http://www.opendesigns.org/ http://www.freecsstemplates.org/http://www.freecsstemplates.org/ http://www.freewebsitetemplates.com/http://www.freewebsitetemplates.com/ More at More at

http://delicious.com/geshan/WebTemplatehttp://delicious.com/geshan/WebTemplatess

Page 9: 10 Email Etc

GeshanManandhar.com 9

Simply theme your codeSimply theme your code

►Download the template you want.Download the template you want.►See the <div> structure.See the <div> structure.►Change the static content to the Change the static content to the

dynamic (PHP) content you want to dynamic (PHP) content you want to replace with.replace with.

►Check your output.Check your output.►Hit and trail works if you are not good Hit and trail works if you are not good

at designing.at designing.

Page 10: 10 Email Etc

GeshanManandhar.com 10

A themed users tableA themed users table

Page 11: 10 Email Etc

GeshanManandhar.com 11

QuestionsQuestions

Page 12: 10 Email Etc

GeshanManandhar.com 12

To doTo do

► Inject your code to a layout from above Inject your code to a layout from above mentioned website.mentioned website.

►Make your login system fully functional.Make your login system fully functional.►Review you code – implement the Review you code – implement the

mantras.mantras.►Assign messageAssign message to a variable $message to a variable $message

as per login information supplied by user, as per login information supplied by user, using the ternary operator.using the ternary operator.

►Upload your files to your newly created Upload your files to your newly created sub-domain at 000webhost, test them.sub-domain at 000webhost, test them.