Reputation: 1062
I've got a simple email form in PHP that is to send a form input to the email address. However, the textarea isn't included. The phone number is being sent, just the textarea is not. Here's my form:
<form id="form1" name="form1" method="post" action="send.php">
<p> <span id="sprytextfield1">Your name:
<label for="name"></label>
<input type="text" name="name" id="name" /></p>
<span class="textfieldRequiredMsg">A value is required.</span></span>
<p><span id="sprytextfield2">
<label for="email">Email address:</label>
<input type="text" name="email" id="email" />
<span class="textfieldRequiredMsg">A value is required.</span></span></p>
<p>
<label for="phone">Phone Number:</label>
<input type="text" name="phone" id="phone" />
</p>
<p><span id="sprytextarea1">
<label for="message">Message</label>
<br />
<textarea name="message" id="message" cols="45" rows="5"></textarea>
<span class="textareaRequiredMsg">A value is required.</span></span></p>
<p>
<input type="submit" name="Submit" id="Submit" value="Submit" />
<br />
</p>
</form>
After that, I have the validation for the form. Here's the php
$name=$_POST[name];
$email=$_POST[email];
$phone=$_POST[phone];
$message=$_POST[message];
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("[email protected]", $subject, $from, $phone, $message);
echo "Email sent!";
Upvotes: 0
Views: 793
Reputation: 1062
This worked, for some reason. Using $subject, $message, $from would only send the message. I got rid of the phone number.
$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Someone from your website is contacting you";
mail("[email protected]", $subject, $from, $message); //weird, but it works
Upvotes: 0
Reputation: 4121
Hmmm, you aren't using parameters in the correct order. As per mail documentation (http://php.net/manual/en/function.mail.php), it should be:
mail("[email protected]", $subject, $message, $from);
I am not sure where you want to use $phone
but may be you can concatenate it to $message
before sending it.
Upvotes: 0
Reputation: 2528
change your
$name=$_POST[name];
$email=$_POST[email];
$phone=$_POST[phone];
$message=$_POST[message];
to
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$message=$_POST['message'];
your message will work with this way
Upvotes: 2