Reputation: 21
I need to take a form with 3-4 fields and have the info sent to two different emails, with different info.
EXAMPLE:
FIELD ONE: NAME
FIELD TWO: EMAIL
FIELD THREE: COMMENT
(When submitted)
EMAIL ONE: JUST FIELD THREE IS SENT
EMAIL TWO: ALL THREE FIELDS ARE SENT
I tried the following:
<?php
if(isset($_POST['submit'])) {
// The message
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$msg1 = $comment;
$msg2 = $name."\n\n".$email."\n\n".$comment;
// Send
mail('[email protected]', 'My Subject', $msg1);
mail('[email protected]', 'My Subject', $msg2);
}
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<form name="frmemail" action="" method="post">
<p>Name: <input type="text" name="name" /></p>
<p>Email: <input type="text" name="email" /></p>
<p>Comment: <textarea name="comment"></textarea></p>
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
</body>
</html>
This works, but the strange thing is:
[email protected] received both EMAIL ONE
and EMAIL TWO
(when it is supposed to receive EMAIL ONE only).
[email protected] received EMAIL TWO only (which what I want).
Can someone tell me why [email protected] received both EMAIL ONE
and EMAIL TWO
?
I tested using gmail.
Thanks in advance.
Upvotes: 2
Views: 1984
Reputation: 430
If it's sending 2 emails, it's because:
The most probable reason is you are calling mail() twice. You can check this using your apache/IIS logs.
Upvotes: 1