Jump to content

Moving variables from a form to be displayed and emailed, Trouble understanding.


horseatingweeds

Recommended Posts

I have an form reach from a 'listing' by this link:

 

<?php echo "<a href='breeder_mail.php?address=" . $email . "

&title=" . $title . "' target='_blank'>Email</a>"; ?>

 

I display the title on the page and add it to an html mail() function and use the address as the send to email address.

 

My first problem is that the title and address disappears when the page is submitted and returned to, like for validation. To fix this I tried $_GETing it to a hidden input, then use an if statement to produce a variable set to the posted hidden data if it is there else the $_GET info in the url.

 

This isn't working.

 

My more important problem is the email that is sent. The variables carrying the address and subject work, but the $body and $headers variable aren't getting the data into the email.

 

Here is the first page: breeder_mail.php

 

<?php

include ('email-form.php');

$name = $_POST['name'];

$subject = $_POST['subject'];

$email = $_POST['email'];

$reenter_email = $_POST['reenter_email'];

$phone = $_POST['phone'];

$message = $_POST['message'];

if (isset($_POST['address']))

{

$breeder_email = $_POST['address'];

}

else

{

$breeder_email = $_GET['address'];

}

if (isset($_POST['title']))

{

$breeder_name = $_POST['title'];

}

else

{

$breeder_name = $_GET['title'];

}

 

 

$headers = "From:[email protected]\r\n";

$headers .= "Reply-To:" . $email . "\r\n";

$headers .= "Content-Type: text/html;\r\n charset=\"iso-8859-1\"\r\n";

 

$body = "

<html>

<head>

<title>GentleDoberman.com Inquiry</title>

</head>

<body>

<p>This is an inquiry from someone who has visited your listing on GentleDoberman.com</p>

<h2>" . $subject . ", " . $name . "</h2>

<p>Phone Number: " . $phone . "</p>

<p>From: " . $email . "</p>

<p>" . $message . "</p>

<p>Always use caution when dealing with inquiries for your Doberman services. Be careful who you trust, there is no shortage of scammers who take advantage of breeders and dog lovers. Never send money to someone you don’t know, through Western Union or other money wiring services.</p>

</body>

</html>

";

mail($breeder_email, "GentleDoberman Inquiry", $body, $headers);

echo $breeder_name;

echo $breeder_address;

 

?>

 

Here is the email-form.php

 

<h2>Please fill out the following form to send a message to:</h2>

<h1><?php echo $breeder_name;?></h1>

 

<form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method = "post" >

<table>

<tr>

<td>

Your Name:<br />

</td>

<td>

<input type='text' name='name' size='40' maxlength='100'

value='<?php echo$_POST['name'];?>' /><br />

</td>

</tr>

 

<tr>

<td>

Subject:<br />

</td>

<td>

<input type='text' name='subject' size='40' maxlength='100'

value='<?php echo$_POST['subject'];?>' /><br />

</td>

</tr>

 

<tr>

<td>

Your Email:<br />

</td>

<td>

<input type='text' name='email' size='40' maxlength='100'

value='<?php echo$_POST['email'];?>' /><br />

</td>

</tr>

 

<tr>

<td>

Re-enter Email:<br />

</td>

<td>

<input type='text' name='reenter_email' size='40' maxlength='100'

value='<?php echo$_POST['reenter_email'];?>' /><br />

</td>

</tr>

 

<tr>

<td>

Phone Number:<br />

</td>

<td>

<input type='text' name='phone' size='40' maxlength='100'

value='<?php echo$_POST['phone'];?>' />

</td>

</tr>

</table>

 

Message:<br />

<textarea name='message' cols=75 rows=10>

<?php echo$_POST['message'];?>

</textarea>

<input type='hidden' name='address' value="<?php echo $breeder_address;?>" />

<input type='hidden' name='address' value="<?php echo $breeder_name;?>" />

<input type='submit' value='Send' />

</form>

 

If this is a simple problem that I should know, feel free to use profanity when answering. ;)

I'm don't use PHP's mail function often, but you might want to try this instead:

 

<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = "From:[email protected]\r\n";
$headers .= "Reply-To:" . $email . "\r\n";
?>

 

It's worth a shot, since nobody else has replied ;)

email-form.php

 

instead of using this ->

<?php echo$_POST['name'];?>

better to use ->

<?=$_POST['name']?>

 

to make sure the POST and GET have a value..

 

print_r($_POST)."<br>";

print_r($_GET)."<br>";

 

if the same problem appears again check the naming convention of the input field...

Thanks for your help thus far fellows, but I'm still not getting anywhere fast. I've figured out the problem with displaying the title and such, but I'm still having the problem with the email not sending.

 

The problem appears when I add variables into the $body variable. If I take them out it send the text and html in the $body variable but when I add in the other variables, it just stops sending.

 

I've made a simpler version as follows:

 

<?php
$message = (isset($_POST['message'])? $_POST['message'] : '');
$email = "[email protected]";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From:[email protected]\r\n";
$headers .= "Reply-To:" . $email . "\r\n";
$body = "
<html>
<head>
</head>
<body>
<p>Part of the body</p>
<p>" . $message . "</p>
</body>
</html>
";
if (isset($_POST['submit']))
{
mail('[email protected]', 'This Subject', $body, $headers);
}
?>
<form>
<input type='text' name='message' size='20' value='' />
<input type='submit' value='test' />
</form>

 

What am I doing wrong here? How do you add variables into a variable that goes into the mail()? Or am I trying the impossible again?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.