...

View Full Version : Email script not retrieving/passing variables



mathruD
09-10-2011, 12:04 AM
I am having a problem getting my php email script to retrieve variables from the email form. The email sends properly, however, it is blank. I've used this same email script before with not problems so I don't know what is going on. Also, whenever the email arrives, it outputs twice, like this:
Sender:
Company:
Sender:
Company:



<fieldset id="loginMenu">

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

<fieldset id="formLeft">

<select name="recipient">
<option value="">Choose a recipient</option>
<option value="recipient_1">Person One</option>
<option value="recipient_2">Person Two</option>
<option value="recipient_3">Person Three</option>
</select>

<label>Name</label>
<input type="text" id="name" name="name" value="" />
<label>Company</label>
<input type="text" id="company" name="company" value="" />
<label>Email</label>
<input type="text" id="email" name="email" value="" />
</fieldset>

<fieldset id="formRight">
<label>Message</label>
<textarea id="comment" name="comment"></textarea>
<input type="image" class="btn" value="Send Message" />
</fieldset>

</form>

</fieldset>

<?php
if (isset($_POST['email'])) {
$subject = "Contact Form";
$email = $_REQUEST['email'] ;
$comment = $_REQUEST['comment'] ;
$message = "$message";
$headers = "From: $name";
$recipients = array(

'recipient_1' => 'email1@email.com',
'recipient_2' => 'email2@email.com',
'recipient_3' => 'email3@email.com'

);

$to = $recipients[$_REQUEST['recipient']];
mail($to, $subject, $message, $headers) ;

if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }
}
?>

Inigoesdr
09-10-2011, 12:13 AM
Your message field is named "comment" but you are trying to send $message as the body text, which is blank. The code should look similar to this:

$subject = "Contact Form";
$email = $_REQUEST['email'] ;
$comment = $_REQUEST['comment'] ;
$headers = "From: $name";
$recipients = array(
'recipient_1' => 'email1@email.com',
'recipient_2' => 'email2@email.com',
'recipient_3' => 'email3@email.com'
);

$to = $recipients[$_REQUEST['recipient']];
mail($to, $subject, $comment, $headers);

mathruD
09-11-2011, 01:01 AM
Your message field is named "comment" but you are trying to send $message as the body text, which is blank. The code should look similar to this:

$subject = "Contact Form";
$email = $_REQUEST['email'] ;
$comment = $_REQUEST['comment'] ;
$headers = "From: $name";
$recipients = array(
'recipient_1' => 'email1@email.com',
'recipient_2' => 'email2@email.com',
'recipient_3' => 'email3@email.com'
);

$to = $recipients[$_REQUEST['recipient']];
mail($to, $subject, $comment, $headers);

thanks. that did work. i don't know how i overlooked that.

however, there is still one slight problem. all of the info is sent just fine, but the header field isn't working properly. no matter what i put in the header field it is showing up as some default address from my hosting account.

it's arriving as, "From: username@pass87.dizinc.com"

what does this mean? or what am i doing improperly to cause this?

thanks for the help so far.

tangoforce
09-11-2011, 02:18 AM
You may need to use the additional paramters parameter then with the -f option.

mathruD
09-15-2011, 10:54 PM
You may need to use the additional paramters parameter then with the -f option.

you are absolutely correct. the additional parameter seemed to fix it. it also appears that there is a specific way that the header has to be written (depending on the hosting provider) in order to display the properly. some ways work and others don't.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum