PDA

View Full Version : Blank PHP Form Emails


PHX22
01-30-2012, 06:59 PM
Salutations!

I have recently had the honor of being introduced to PHP and it's been a pain. I've read numerous other forums and threads referring to the Blank E-mail problem but still have not been able find a solution to mine.

Here is the PHP. I've disregarded the $results as it is working properly.

<?php

$emailSubject = 'Information Request';
$mailto = 'admin@mysite.com';



$nameField = $_POST ['name'];
$companyField = $_POST['company'];
$address_1Field = $_POST ['address_1'];
$address_2Field = $_POST ['address_2'];
$cityField = $_POST['city'];
$stateField = $_POST ['state'];
$countryField = $_POST ['country'];
$phoneField = $_POST['phone'];
$workphoneField = $_POST ['workphone'];
$emailField = $_POST ['email'];
$questionField = $_POST ['question'];


$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Email: $emailField <br>
Company: $companyField <br>
Address_1: $address_1Field <br>
Address_2: $address_2Field <br>
City: $cityField <br>
State1: $stateField <br>
Country: $countryField <br>
Phone: $phoneField <br>
Work_Phone: $workphoneField <br>
Questions: $questionField <br>
EOD;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($mailto, $emailSubject, $body, $headers);


$theResults = <<<EOD



I greatly appreciate all replies!

edbr
01-31-2012, 12:08 AM
odd because this works




<form action="" method="POST">




<label> email</label><input name="email" type="text">
<label> first tname</label><input name="name" type="text">
<label>last name</label><input name="company" type="text">
<label>telephone</label><input name="address_1" type="text">
<label>comments</label><textarea name="address_2" cols="8" rows="8"></textarea>
<input name="Send" class="button" type="submit" value="Submit">

</form>






<?php

$emailSubject = 'Information Request';
$mailto = 'admin@mysite.com';



$nameField = $_POST ['name'];
$companyField = $_POST['company'];
$address_1Field = $_POST['address_1'];
$address_2Field = $_POST['address_2'];
$cityField = $_POST['city'];
$stateField = $_POST['state'];
$countryField = $_POST['country'];
$phoneField = $_POST['phone'];
$workphoneField = $_POST['workphone'];
$emailField = $_POST['email'];
$questionField = $_POST['question'];


$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Email: $emailField <br>
Company: $companyField <br>
Address_1: $address_1Field <br>
Address_2: $address_2Field <br>
City: $cityField <br>
State1: $stateField <br>
Country: $countryField <br>
Phone: $phoneField <br>
Work_Phone: $workphoneField <br>
Questions: $questionField <br>
EOD;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";

//commented out for testing
//$success = mail($mailto, $emailSubject, $body, $headers);


echo $body;
?>

PHX22
01-31-2012, 04:26 AM
Thank you for the reply...I don't quite understand what you mean with the form HTML...

<form action="" method="POST">




<label> email</label><input name="email" type="text">
<label> first tname</label><input name="name" type="text">
<label>last name</label><input name="company" type="text">
<label>telephone</label><input name="address_1" type="text">
<label>comments</label><textarea name="address_2" cols="8" rows="8"></textarea>
<input name="Send" class="button" type="submit" value="Submit">

</form>

I tried removing //Commented out for test //$success = mail($mailto, $emailSubject, $body, $headers); And still a blank form ends up in my spam box.

edbr
01-31-2012, 05:36 AM
to send mail it should be

<?php
remove comments so it should be
$success = mail($mailto, $emailSubject, $body, $headers);

?>

do your form fields math names you show in you definitions?
post your form

PHX22
01-31-2012, 03:18 PM
That's what I've got for the $success line, and here is the form. I believe they all match up, unless I've missed something bigger.

<form id="form1" name="form1" method="POST" enctype="application/x-www-form-urlencoded" action="form_mailer.php">
<p>
<label>Please Enter Name Here</label>
<input name="name" type="text" id="name" accesskey="1" tabindex="1" onblur="MM_validateForm('name','','R','email','','RisEmail ');return document.MM_returnValue" size="20" />
</p>
<p>&nbsp;</p>
<p>
<label>Company </label>
<input name="company" type="text" id="company" accesskey="2" tabindex="2" size="20" />
</p>
<p>&nbsp;</p>
<p>
<label>Address Line 1</label>
<input name="address_1" type="text" id="address_1" accesskey="3" tabindex="3" size="20" />
</p>
<p>&nbsp;</p>
<p>
<label>Address Line 2</label>
<input name="address2" type="text" id="address2" accesskey="4" tabindex="4" size="20" />
</p>
<p>&nbsp;</p>
<p>
<label>City</label>
<input name="city" type="text" id="city" accesskey="5" tabindex="5" size="20" />
</p>
<p>&nbsp;</p>
<p>
<label>State or Province</label>
<input name="state" type="text" id="state" accesskey="6" tabindex="6" size="5" />
</p>
<p>&nbsp;</p>
<p>
<label>Country</label>
<input name="country" type="text" id="country" accesskey="7" tabindex="7" size="20" />
</p>
<p>&nbsp;</p>
<p>
<label>Zip Code</label>
<input name="zip" type="text" id="zip" accesskey="8" tabindex="8" size="20" maxlength="9" />
</p>
<p>&nbsp;</p>
<p>
<label>Home Phone</label>
<input name="phone" type="text" id="phone" accesskey="9" tabindex="9" value="" size="20" maxlength="15" />
</p>
<p>&nbsp;</p>
<p>
<label>Work Phone</label>
<input name="workphone" type="text" id="workphone" accesskey="10" tabindex="10" size="20" maxlength="15" />
</p>
<p>&nbsp;</p>
<p>
<label>E-mail Address</label>
<input name="email" type="text" id="email" accesskey="11" tabindex="11" size="20" />
</p>
<p>&nbsp;</p>
<p>
<label>Any comments or questions go here</label>
<textarea name="questions" cols="45" rows="5" id="questions" accesskey="13" tabindex="13"></textarea>
</p>
<p>&nbsp;</p>
<p>
<input type="submit" name="submit form" id="submit" value="Submit Form" accesskey="14" tabindex="14" />
<input type="reset" name="clear" id="clear" value="Clear Form" accesskey="15" tabindex="15" />
</p>
</form>

PHX22
01-31-2012, 04:03 PM
@edbr, thank you for your replies and help, I scoured over the code and changed a couple things on the form page and it worked. Been facing this issue a while now, I'm pumped. Thanks again!

-Cheers