/    Sign up×
Community /Pin to ProfileBookmark

Where’d my variables go?

My form:

[code]<form action=”mailtoenquire.php” method=”POST”>
Name: <br/><input type=”text” name=”name”/><br/>
Company: <br/><input type=”text” name=”company”/><br/>
Email: <br/><input type=”text” name=”email”/><br/>
Phone number:<br/><input type=”text” name=”telnum”/><br/>
Fax:<br/><input type=”text” name=”faxnum”><br/>
Enquiry: <br/><textarea rows=”15″ cols=”80″ name=”enquiry”/></textarea><br/>
<input type=”submit” value=”Send” id=”sendbutton”/>
</form>[/code]

My script:

[code]<?php

$name = ‘From: ‘.$REQUEST[‘name’].'<br/>’;
$company = $_REQUEST[‘company’];
$emailaddress = $_REQUEST[’email’];
$telno = ‘Telephone: ‘.$_REQUEST[‘telnum’].'<br/>’;
$faxno = ‘Fax: ‘.$_REQUEST[‘faxnum’].'<br/>’;
$enquiry = $_REQUEST[‘enquiry’];

$recepitant = ‘[email protected]’;

$header = $name.$faxno.$telno;

$subject = ‘Enquiry from: ‘.$company.”;

//if (preg_match($regexp, $email)){

mail($recepitant,$subject,$enquiry, $header);

echo ‘Mail Sent. Click <a href=”index.html”>here</a> to return.’;

/*}
else {
echo ‘Mail sending failed.’;
}*/
?>
[/code]

And here is my output in an email:

From:
Fax:
Telephone:

Where did the variables go? (NOTE: I know that code is open to an email injection, I’m just dumbing it down to find the problem).

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@StettinFeb 02.2009 — try using $_POST array rather than $_REQUEST (also your first one is $.REQUEST)
Copy linkTweet thisAlerts:
@Mr__E__CrypticFeb 02.2009 — All you seem to be sending as the body of the email is the posted value from the text area named enquiry:

$enquiry = $_REQUEST['enquiry'];

mail('[COLOR="Red"]the recips email address[/COLOR]','[COLOR="#ff0000"]the subject[/COLOR]','[B][COLOR="Lime"]the email body[/COLOR][/B]','[COLOR="#ff0000"]additional headers[/COLOR]')]

you need to build the body from you user's input:

[code=php]
<?php
$user['name'] = $_POST['name'];
$user['email'] = $_POST['email'];
$emailBody = 'Name: ' . $user['name'] . "n" . 'Email: ' . $user['email'];
?>
[/code]


Also, the 4th param of the mail function is to set email headers, eg:

From: Name<[email protected]>

CC: [email][email protected][/email]

You seem to be sending a string made up of the post values from name, faxnum & telnum?
Copy linkTweet thisAlerts:
@StephanauthorFeb 02.2009 — I've come to the conclusion that either the script doesn't know it is called by the form, or there's something wrong with the server.

try using $_POST array rather than $_REQUEST (also your first one is $.REQUEST)[/QUOTE]

They were originally $_POST, but I changed when nothing was coming through.

Thanks for pointing out the mistake in the first one.
Copy linkTweet thisAlerts:
@skywalker2208Feb 02.2009 — Have you tried doing a print_r on the $_POST variable at the top of the page?
Copy linkTweet thisAlerts:
@darthnuriFeb 03.2009 — $name = 'From: '.$REQUEST['name'].'&lt;br/&gt;';

no such thing as $REQUEST, that's probably what breaks the first one. ?
Copy linkTweet thisAlerts:
@skywalker2208Feb 03.2009 — $name = 'From: '.$REQUEST['name'].'&lt;br/&gt;';

no such thing as $REQUEST, that's probably what breaks the first one. ?[/QUOTE]


Was already reported in a few post up.
×

Success!

Help @Stephan 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.18,
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,
)...