sharable function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Lphp
Forum Commoner
Posts: 74
Joined: Sun Jun 26, 2011 9:56 pm

sharable function

Post 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? :(
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: sharable function

Post 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);
}
(#10850)
Lphp
Forum Commoner
Posts: 74
Joined: Sun Jun 26, 2011 9:56 pm

Re: sharable function

Post by Lphp »

if I want to put the function on separate mail.php , how can I involve it on index.php
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: sharable function

Post 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);
}
(#10850)
Post Reply