Forum Moderators: coopster

Message Too Old, No Replies

Simple form to email issue

Does mail only allow 3 values?

         

erdy

10:13 pm on Oct 5, 2007 (gmt 0)

10+ Year Member



Hi,

I am creating a contact us page with a html form.
This form will send out to email through PHP script.
I understand very little PHP at the moment but have managed to fudge this simple script together from other bits and bobs I have found on the internet.
The problem is that it will only send three of the four fields in the form to the email address.
Is this a problem with the Mail function?
If so how do I solve this? Surely theres an easy way to do a form to email for as many fields as you want.
Below is the mark up and PHP.

********MARK UP**********

<form method="post" action="send_comments.php">

<fieldset>

<legend>Your Details</legend>

<p>Contact Name:<input type="text" name="visitors_name"/></p>
<hr>
<p>Email:<input type="text" name="visitors_email"/></p>
<hr>
<p>Telephone:<input type="text" name="telephone"/></p>
<hr>
<p>Comments: <textarea name="comments"></textarea></p>

<input type="submit" class="submit" name="submit" value="Submit"/>

</fieldset>

</form>

********PHP**********


<?php

$email = 'email@example.co.uk';
$visitors_email = $HTTP_POST_VARS['visitors_email'];
$visitors_name = $HTTP_POST_VARS['visitors_name'];
$comments = $HTTP_POST_VARS['comments'];
$telephone = $HTTP_POST_VARS['telephone'];

if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $visitors_email)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($visitors_name == "") {
echo "<h4>No Name Pal</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}

elseif (mail($email,$visitors_name,$comments,$telephone,$visitors_email)) {
echo "<h4>Thank you for your correspondence.</h4><h4>Your message will be dealt with shortly.</h4>";
} else {
echo "<h4>Can't send email to IDP</h4>";
}
?>

Please help if you can.

Regards

Erdy.

[edited by: eelixduppy at 12:38 pm (utc) on Oct. 6, 2007]
[edit reason] removed email [/edit]

cameraman

5:42 am on Oct 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The prototype for mail() [php.net] is:

bool mail ( string $to, string $subject, string $message [, string $additional_headers [, string $additional_parameters]] )

So you would want to put your stuff together in $message, perhaps something like:
$message = "From $visitors_email\n";
$message .= "Name: $visitors_name\n";
$message .= "Telephone: $telephone\n";
$message .= "Comments:\n";
$message .= $comments;

Then you send it:
.
.
elseif(mail($email,"New contact",$message)) {
echo 'thanks';
else {
echo "can't email";
}

erdy

11:14 am on Oct 6, 2007 (gmt 0)

10+ Year Member



Thanks Cameraman, that worked perfectly.

Regards

Erdy.