Sending an e-mail in PHP is another relatively simple task. An e-mail is sent through PHP using the mail() function.
[php]mail($address, $subject, $body);[/ph]
When using this function, $address should contain the e-mail address of the recipient. $subject should contain the subject heading of the e-mail. $body should contain the actual contents of the e-mail.
The following is an example of code that uses the mail() function:
[php]mail("email@example.com","My Subject", "Line1 \n Line2 \n Line3");[/php]
Note that, in the above example, /n is used to separate the different lines in the body of the e-mail. Since sending an e-mail that contains only one line would be inefficient, it is important to use these constructions to make larger e-mails easier to read.
Another common operation is concatenate-equals (.=). This operation takes the contents of the variable to the left of the operator and concatenates it with whatever is to the right. For example, consider the following code:
[php]$example1 = "straw";
$example2 = "berry";
$example1 .= $example2; [/php]
After executing this code, the variable $example1 will contain the string "strawberry". Below, we can see an example of how this would be used in the mail() function:
$mailto = $email;
$subject = "Thank you for signing up for our conference";
$body = "Hello ".$fname." ".$lname.",\n\n";
$body .= "Thank you for registering for our conference on \n";
$body .= "May 22nd, 2002 at Union College. We hope that this\n";
$body .= "will be an enjoyable experience. We look foreword to \n";
$body .= "seeing you there.\n\n";
$body .= "Thank You,\n";
$body .= "The Management\n";
Be creative! You can use information collected from forms as well as other data to send an e-mail to yourself or to a visitor that has just filled out a survey.