I'm learning PHP and working on some basic functions. I was wondering why my send message function doesn't work.
I have 2 PHP files:
- One to process the login and
- One to process the message.
Any advice?
index.php
<form name="admin" method="POST" action="process.php">
<div>
<label for="login">Login: </label>
<input type="text" name="login" placeholder="Login"/>
</div>
<div>
<label for="password">Password: </label>
<input type="text" name="password" placeholder="Password"/>
</div>
<div>
<input type="submit" name="submit" value="Submit">
</div>
</form>
<br>
<form name="sendmail" method="POST" action="sendmail.php">
<div>
<p><b>Send me a message:</b></p>
<textarea name="message"></textarea>
</div>
<div><input type="submit" name="submit" value="Send"></div>
</div>
</form>
sendmail.php
<?php
$message = '';
foreach($_POST as $name=>$value){
if('submit'!=$name){
if(is_array($value)){
/* SYNTAX: implode(separator,array) -
converts an array of values as a string. */
$value=implode(', ', $value);
}
$message .= ucfirst($name) ."is $value.\n\n";
}
}
$to = 'testemail@test.org';
$subject = 'Form submission from webapp';
if (mail($to, $subject, $message)){
echo "Your message has been sent.";
};
?>