Page 1 of 1

Will only show me 3 variable?

Posted: Mon Nov 08, 2010 6:00 pm
by tkowebworks
Hello,

I am writing my first php script (of course) and it works except it only shows 3 variables.
Example I have it to send me:
mail($myemail, $fullname, $email, $message, $phone);
But it will only send me the first four no matter what order they are in. It's driving me crazy. I can't think or find any reason why it would do this.

If I change it to
mail($myemail, $fullname, $email, $phone, $message);
It will send me everything but $message
or if I change it to
mail($myemail, $fullname, $message, $email, $phone, );
It will send me everything but $phone

Does anyone know why or what I need to change? I apologize if this sounds like a dumb question. I am very very new to php.

Thank you for any guidance you can give. Here is the code:
HTML:

<form action="Contact.php" method="post" id="contact" name="contact" style="margin:0px";>
<h2>Contact Form:</h2>
<p>Fields marked (<span style="color:#F00;">*</span>) are required.</p>

<p>
<label for="text_fullname">Full Name<span style="color:#F00;">*</span>:</label>
<input name="fullname" type="text" class="input" id="fullname" tabindex="1" />
<br />

<label for="text_email">Email<span style="color:#F00;">*</span>:</label>
<input name="email" type="text" class="input" id="email" tabindex="2" />
<br />

<label for="text_phone">Phone:</label>
<input name="phone" type="text" class="input" id="phone" tabindex="3" />
<br />

<label for="text_comments">Message/Comment:</label>
<textarea name="message" cols="23" rows="3" class="input" id="message" tabindex="4"></textarea>
<br>


<div style="padding-left:200px;">
<button type="submit" id="send" name="send">Send!</button> &nbsp;&nbsp; <button type="reset">Reset</button>
</div>

</fieldset>
</form>
---------------------------------------
PHP:
<?php
/* Set e-mail recipient */
$myemail = "mymail@gmail.com";

$fullname = $_POST['fullname'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$message = $_POST['message'] ;


mail($myemail, $fullname, $email, $message, $phone);

header( "Location: http://www.ppm-oc.com/thankyou.html" );
?>
----------------------------------

Thank you :)

Re: Will only show me 3 variable?

Posted: Mon Nov 08, 2010 7:22 pm
by awebtech
Hi, please revise mail() function description http://ru.php.net/manual/en/function.mail.php

The correct variant is like this:

Code: Select all

$msg = 'Name: '.$fullname."\n";
$msg .= 'Email: '.$email."\n";
$msg .= 'Phone: '.$phone."\n\n";
$msg .= 'Message: '.$message."\n";

mail($myemail, 'New message from contact form', $msg);

Re: Will only show me 3 variable?

Posted: Mon Nov 08, 2010 11:03 pm
by tkowebworks
Thank you SO much. That was very very helpful!
This is what I ended up with that worked for me, but I'm not sure if I'm writing my code correct:

<?php
$myemail = "mymail@gmail.com";

$fullname = $_POST['fullname'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$message = $_POST['message'] ;

$msg = 'Name: '.$fullname."\n";
$msg .= 'Email: '.$email."\n";
$msg .= 'Phone: '.$phone."\n\n";
$msg .= 'Message: '.$message."\n";

mail($myemail, 'New message from contact form', $msg);
header( "Location: http://www.ppm-oc.com/thankyou.html" );
?>

Re: Will only show me 3 variable?

Posted: Tue Nov 09, 2010 1:15 am
by awebtech
tkowebworks, you are welcome.

Your new code looks fine, the only we could do is to reduce some redundancy:

Code: Select all

<?php
	
	$myemail = "mymail@gmail.com";

	$msg = 'Name: '.$_POST['fullname']."\n";
	$msg .= 'Email: '.$_POST['email']."\n";
	$msg .= 'Phone: '.$_POST['phone']."\n\n";
	$msg .= 'Message: '.$_POST['message']."\n";

	mail($myemail, 'New message from contact form', $msg);
	header( "Location: http://www.ppm-oc.com/thankyou.html" );
	
?>
BTW: if you will follow the rules of this post , code in your posts will be much more readable and other members will have more motivation to help :wink: