Page 1 of 1

sharable function

Posted: Fri Dec 02, 2011 3:44 am
by Lphp
if I need to use this part of code a few time , call i make it as function, or including able page
if($A !=$B){
$to = "{$mail}";
$subject = "subject";
$message = "Hi {$name}, how are you";
$from = "asp@hotmail.com ";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
}
how to do that? :(

Re: sharable function

Posted: Fri Dec 02, 2011 3:43 pm
by Christopher

Code: Select all

function mymail($mail, $from, $message) {
   $to = "{$mail}";
   $subject = "subject";
   $message = "Hi {$name},   how are you";
   $from = "asp@hotmail.com ";
   $headers = "From: $from";
   return mail($to,$subject,$message,$headers);
}

if($A !=$B){
     mymail($to, $from, $message);
}

Re: sharable function

Posted: Mon Dec 05, 2011 7:36 pm
by Lphp
if I want to put the function on separate mail.php , how can I involve it on index.php

Re: sharable function

Posted: Tue Dec 06, 2011 12:59 am
by Christopher
File: mail.php

Code: Select all

<?php
function mymail($mail, $from, $message) {
   $to = "{$mail}";
   $subject = "subject";
   $message = "Hi {$name},   how are you";
   $from = "asp@hotmail.com ";
   $headers = "From: $from";
   return mail($to,$subject,$message,$headers);
}
File: index.php

Code: Select all

<?php
include 'mail.php';

if($A !=$B){
     mymail($to, $from, $message);
}