Forum Moderators: coopster

Message Too Old, No Replies

PHP Mail

         

paseo

11:39 pm on Jan 7, 2007 (gmt 0)

10+ Year Member



Is there a way to echo a variable into the Message portion of the mail statement below? For example, if the First name variable is $firstname, is there a way to echo the result of the $firstname variable into the Message Portion of the mail.

Change This

<?php
mail('email@email.com', 'Subject', 'Message');
?>

Into

<?php
mail('email@email.com', 'Subject', '$firstname');
?>

eelixduppy

11:42 pm on Jan 7, 2007 (gmt 0)



Sure. You could define a message variable and then send that:

$message = "Hello $firstname! How are you doing today?";
[url=http://us3.php.net/manual/en/function.mail.php]mail[/url]('email@example.com', 'Subject', $message);

Also, take a look at these two threads, assuming you are going to have a form ;):
Basics of Submitting and Emailing Forms with PHP [webmasterworld.com]
Combatting Webform hijack [webmasterworld.com]

paseo

11:49 pm on Jan 7, 2007 (gmt 0)

10+ Year Member



What if i wanted to include 2 variables

mail('email@email.com', 'Subject', $firstname$lastname);

scriptmasterdel

11:50 pm on Jan 7, 2007 (gmt 0)

10+ Year Member



Then you would need to seperate them with a full stop.

mail('email@email.com', 'Subject', $firstname.$lastname);

eelixduppy

11:51 pm on Jan 7, 2007 (gmt 0)



Same thing. You can include as many variables as you want into the message body:

$message = "Hello $firstname $lastname! How are you doing today? You last visited $last_visited. Is this correct? Your mother's name is $mother and your father's name is $father. And $answer I $answer_grammar stalk people for a living!";

;)

paseo

11:52 pm on Jan 7, 2007 (gmt 0)

10+ Year Member



that worked perfect! You guys are awesome. Have a Great Weekend!

eelixduppy

12:05 am on Jan 8, 2007 (gmt 0)



>>Have a Great Weekend!

It's Monday tomorrow ;) But you too!...hehe