Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Function in message

the mail() function

Moderators: macek, egami, gesf

Function in message

Postby Speegster » Thu Mar 17, 2005 12:54 am

I'm having problem with including a user-defined function in the mail() function.

An example code would be:
Code: Select all
<?php

function Func($text = 'hello')

{
echo $text;
};

$message = Func();

mail('example@example.com', 'Your email', $message);

?>


When I execute the script, the defined function is carried out on the page and the email is blank. How can I get the $text to show in the email, and not on the page? Any ideas?
Speegster
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Mar 04, 2005 2:18 am

Postby Shiv » Thu Mar 17, 2005 2:17 am

I think return statement is missing in function.

I m not quite right but i think so.
User avatar
Shiv
php-forum Active User
php-forum Active User
 
Posts: 262
Joined: Wed Feb 02, 2005 8:06 pm
Location: Ahmedabad (Gujarat), INDIA

Postby Alexej Kubarev » Thu Mar 17, 2005 4:16 am

You will need to get a basic understanding of how functions work... you may define functions in 2 types... those that return some value (has return statement) and the void functions -- those that do something..for instance ouputs something...

In your case you need a return type of function... so you will need to use

rerutn $text; instead of echo $text..

echo $text will make it a void..

if it is a void -- you will not be able to give another variable the value...
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby Shiv » Thu Mar 17, 2005 7:57 pm

Yesssss I was right.

write

return $text;

in function body at end. :grin:
User avatar
Shiv
php-forum Active User
php-forum Active User
 
Posts: 262
Joined: Wed Feb 02, 2005 8:06 pm
Location: Ahmedabad (Gujarat), INDIA


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.