/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] PHP form problems

Hi all,

I’m not sure what i’m doing wrong as this code normally works for me but it isn’t this time. Maybe i’ve missed something and because i’ve been starring at it for the last 3hrs i’ve gone cross eyed.

Here’s my code, any help would be much appreciated: –

[COLOR=”Blue”]<form action=”sendmail.php” method=”post”>
<p>Name:</p>
<input class=”form” name=”name” type=”text” /><br />
<p>Address:</p>
<textarea class=”form” name=”address” rows=”3″></textarea><br />
<p>Contact Number:</p>
<input class=”form” name=”tel” type=”text” /><br />
<p>Email Address:</p>
<input class=”form” name=”email” type=”text” /><br />
<p>Reason for contact:</p>
<select class=”form” name=”reason”>
<option selected=”selected”>Please select</option>
<option>example1</option>
<option>example2</option>
<option>example3</option>
</select><br />
<p>Message:</p>
<textarea class=”form” name=”message” rows=”3″></textarea>
<input name=”submit” type=”submit” value=”Submit” /><input name=”reset” type=”reset” value=”Reset” />
</form>

<?php
$email = $_REQUEST[’email’] ;
$message = $_
POST[‘message’] ;
$name = $_POST[‘name’] ;
$address = $_
POST[‘address’] ;
$tel = $_POST[‘tel’] ;
$reason = $_
POST[‘reason’] ;

$Body = “<b>WEBSITE ENQUIRY</b><br />”;
$Body .= “n”;
$Body .= “<b><font size 1>Name: </font></b>”;
$Body .= $name;
$Body .= “n<br />”;
$Body .= “<b><font size 1>Address: </font></b>”;
$Body .= $address;
$Body .= “n<br />”;
$Body .= “<b><font size 1>Tel Number: </font></b>”;
$Body .= $tel;
$Body .= “n<br />”;
$Body .= “<b><font size 1>E-Mail: </font></b>”;
$Body .= $email;
$Body .= “n<br />”;
$Body .= “<b><font size 1>Reason for contact: </font></b>”;
$Body .= $reason;
$Body .= “n<br />”;
$Body .= “n<br />”;
$Body .= “<b><font size 1>Message: </font></b>”;
$Body .= “n<br />”;
$Body .= $message;

mail( “[email protected]“, “Enquiry Form Results”,
$Body, “From: $emailrnContent-type: text/html; charset=utf-8”);
header( ‘Location: thankyou.php’ );
?>[/COLOR]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@Phill_PaffordMar 23.2009 — I could be wrong but I think it's your header value not being passed correctly.

[code=php]
<form action="sendmail.php" method="post">
<p>
Name:
</p>
<input class="form" name="name" type="text" />
<br/>
<p>
Address:
</p>
<textarea class="form" name="address" rows="3">
</textarea>
<br/>
<p>
Contact Number:
</p>
<input class="form" name="tel" type="text" />
<br/>
<p>
Email Address:
</p>
<input class="form" name="email" type="text" />
<br/>
<p>
Reason for contact:
</p>
<select class="form" name="reason">
<option selected="selected">Please select</option>
<option>example1</option>
<option>example2</option>
<option>example3</option>
</select>
<br/>
<p>
Message:
</p>
<textarea class="form" name="message" rows="3">
</textarea>
<input name="submit" type="submit" value="Submit" />
<input name="reset" type="reset" value="Reset" />
</form>

<?php
$email = $_REQUEST['email'];
$message = $_POST['message'];
$name = $_POST['name'];
$address = $_POST['address'];
$tel = $_POST['tel'];
$reason = $_POST['reason'];



$Body = "<b>WEBSITE ENQUIRY</b><br />";
$Body .= "n";
$Body .= "<b><font size 1>Name: </font></b>";
$Body .= $name;
$Body .= "n<br />";
$Body .= "<b><font size 1>Address: </font></b>";
$Body .= $address;
$Body .= "n<br />";
$Body .= "<b><font size 1>Tel Number: </font></b>";
$Body .= $tel;
$Body .= "n<br />";
$Body .= "<b><font size 1>E-Mail: </font></b>";
$Body .= $email;
$Body .= "n<br />";
$Body .= "<b><font size 1>Reason for contact: </font></b>";
$Body .= $reason;
$Body .= "n<br />";
$Body .= "n<br />";
$Body .= "<b><font size 1>Message: </font></b>";
$Body .= "n<br />";
$Body .= $message;

$to = "[email protected]";
$subject = "Enquiry Form Results";
$from = "[email protected]";
$headers = "From: " . $email . "rnContent-type: text/html; charset=utf-8";

mail($to,$subject,$body,$headers);
header( 'Location: thankyou.php' );
?>
[/code]
Copy linkTweet thisAlerts:
@W444YN3-31authorMar 23.2009 — Hi Phil,

That didn't seem to work either. Like with how mine was, the form gets submitted and it seems to get acknowledged and goes to thankyou.php but i just don't get the e-mail.
Copy linkTweet thisAlerts:
@Phill_PaffordMar 23.2009 — I would suggest printing out the variables your using for the mail script

[code=php]
$email = $_REQUEST['email'] ;
$message = $_POST['message'] ;
$name = $_POST['name'] ;
$address = $_POST['address'] ;
$tel = $_POST['tel'] ;
$reason = $_POST['reason'] ;

echo $email . "<br />";
//etc...
[/code]
Copy linkTweet thisAlerts:
@JunkMaleMar 23.2009 — You will need to check with your web host because not all hosts are created equal and some require additional objects fore and aft the mail() function, one host I used required this menthod as well as having an actual email account for the mail() function to operate properly.
Copy linkTweet thisAlerts:
@W444YN3-31authorMar 24.2009 — Cheers all.

I took your advice JunkMail and contacted the host and it turned out i needed a "fifth element" which was this: - [COLOR="Blue"]"-f".$_REQUEST[email][/COLOR]

Cheers
Copy linkTweet thisAlerts:
@JunkMaleMar 24.2009 — LOL, mail / male...

Anyway, NP, glad it worked out.
×

Success!

Help @W444YN3-31 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.11,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...