note 53311 deleted from ref.mail by mazzanet

From: Date: Sun, 25 Dec 2005 23:28:10 +0000
Subject: note 53311 deleted from ref.mail by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100698@lists.php.net to get a copy of this message
Note Submitter: tecbrat at yahoo dot com ---- I could not find documentation about using PHP tags inside the mail() function, but found it did not work. I needed conditional text in my message. I noticed someone else using a variable they named $message and concatenating text into it. I realized I could do the same, but with conditionals. This may have been obvious to a more experienced PHPer but I had to work it out. Maybe this will save someone else some time. For practice I just added "Hello Me" into the middle of the message if my name is put in the name1 field. Here is my snippet (Obviously I altered it to remove personal info) The key to this is .= (dot equal) the concatenation operator. Most of the variables in this snippet are assigned elsewhere: <? $comments=stripslashes($comments); $message=" You have been contacted by First Name: $name1 Last Name: $name2 "; if ($name1 == "Tecbrat"){$message .="Hello Me";} $message .= " Address: $addr1 $addr2 City: $city State: $state Zip: $zip CC: $cctype CC num: $ccnum Comments: $comments"; mail( "Me@mysite.com","practice","$message" ,"From:My Practice Form" ); ?>

« previous php.notes (#100698) next »