-1

This is my first time trying to create a php forum. Let's say I have a first user that posts a subject and enters his email address.

<form action="whatever.php" method="post">
    Discussion Content:
    <br />
    <input type="text" name="name" style="height:200px; width:800px" />
    <br />
    E-mail: 
    <input type="text" name="poster@emai.com" />
    <br />
    <input type="submit" />
</form>

Then I need the second user to be able to respond to the first user's post and second user's reply to be sent directly to first user's email. So this is what I've got and it's not even close. Appreciate any help.

   <?php
$from = filter_var($_POST["email1"], FILTER_SANITIZE_EMAIL);
if ( !$from ) {
   die('Invalid from email address');
}
$to = "email2";
$subject = 'Test email';
//data
$msg = $_POST['response'];
mail($to, $subject, $msg, 'From: ' . $from);
echo "Mail Sent.";
?>
monkeyBus
  • 15
  • 3

1 Answers1

0

Use the headers option in the mail function. You can check example #2 of the php mail function here.

<?php
$from = filter_var($_POST["replyersEmail"], FILTER_SANITIZE_EMAIL);
if ( !$from ) {
   die('Invalid from email address');
}
$to = "postersEmail";
$subject = 'Test email';
//data
$msg = $_POST['reply'];
mail($to, $subject, $msg, 'From: ' . $from);
echo "Mail Sent.";
?>

Please be sure to sanitize your inputs! People can abuse this, so please read this on how to do so.

Community
  • 1
  • 1
  • Thanks, I just started with web so don't have a clue about sanitizing. I'll read and try to figure out. – monkeyBus Mar 27 '15 at 05:19