/    Sign up×
Community /Pin to ProfileBookmark

PHP form to email not showing the message

Hey guys I have this form on a website that will be sent to an email after the user submits the form…it shows up in the email inbox fine…however the message doesn’t show anything…I have no clue….also How would I redirect the php page after sending it to the email?..thanks ahead of time for the help guys

CODE: mailform.php (the html form is really basic you can get what it is just from the top part of the code)

<?php
$firstName = $_POST[‘firstName’];
$lastName = $_
POST[‘lastName’];
$email = $_POST[’email’];
$phoneNumber = $_
POST[‘phonenumber’];
$previouscustomer = $_POST[‘previouscustomer’];
$message = $_
POST[‘message’];

$to = ‘[email protected]‘ . ‘, ‘;

$subject = ‘Steam King got a new message!’;

$messageBody = ‘$message’ . ‘, ‘;

$headers = ‘MIME-Version: 1.0’ . “rn”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “rn”;

$headers .= ‘To: Steam King <[email protected]>’ . “rn”;
$headers .= ‘From: $email’ . “rn”;

mail($to, $subject, $messageBody, $headers);
?>

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@beau_kangNov 27.2011 — [code=php]
$messageBody = $message . ', ';
[/code]


Try that and see if it works. I find that putting quotes around the variables tends to cause more problems than it's worth, try and practice keeping your variables out and you might find that you have less errors like this.
Copy linkTweet thisAlerts:
@repeater09authorNov 27.2011 — hello,

That did not work....I still get the same problem of the message not being sent....anything else it could be?...I also need to know how to do the redirect to another page
Copy linkTweet thisAlerts:
@beau_kangNov 28.2011 — What is your error saying exactly? Just that it's not sending or that something is breaking the code? Cause looking at your code, it should be like this, correct?

[code=php]
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$phoneNumber = $_POST['phonenumber'];
$previouscustomer = $_POST['previouscustomer'];
$message = $_POST['message'];

$to = "[email protected]";

$subject = "Steam King got a new message!";

$messageBody = $message . ", ";

$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";

$headers .= "To: Steam King <[email protected]>rn";
$headers .= "From: " . $email . "rn";


mail($to, $subject, $messageBody, $headers);
[/code]
Copy linkTweet thisAlerts:
@criterion9Nov 28.2011 — What does the html for the form look like? Maybe the field isn't called "message" like your code expects?
Copy linkTweet thisAlerts:
@repeater09authorNov 30.2011 — yeah thats what the code is suppose to look like...i dont get any errors at all...it sends just fine with no problem but when i check the email there is no message....no nothing just blank

here is the form

<p class="mainContentTitle">Contact Us</p>

<p class="mainContentInfo">

<form id="mailform" name="mailform" method="post" action="../mailform.php">

<input type="hidden" name="subject" value="Form Submission" />

<input type="hidden" name="redirect" value="../index.html" />

<table width="466" border="0">
<tr>
<td width="144">First Name:</td>
<td width="312"><label for="firstName"></label>
<input type="text" name="firstName" id="firstName" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><label for="lastName"></label>
<input type="text" name="lastName" id="lastName" /></td>
</tr>
<tr>
<td>Phone Number:</td>
<td><label for="phoneNumber"></label>
<input type="text" name="phoneNumber" id="phoneNumber" /></td>
</tr>
<tr>
<td>E-Mail:</td>
<td><label for="email"></label>
<input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td>Previous Customer:</td>
<td><input type="radio" name="previousCustomer" id="yes" value="yes" />
<label for="yes">Yes
<input type="radio" name="radio" id="no" value="no" />
No</label></td>
</tr>
<tr>
<td>Message:</td>
<td><label for="message"></label>
<textarea name="message" id="message" cols="45" rows="5"></textarea></td>
</tr>
</table>
<input name="submit" type="submit" class="submitButton" value="Submit" />
<input name="reset" type="reset" class="submitButton" value="Reset" />

</form>

</p>

</div>
Copy linkTweet thisAlerts:
@criterion9Nov 30.2011 — Does the email client you are reading the messages on handle html emails? It doesn't look like you are sending a multi-part message with a text only version in addition to the "html" (which is solely what a customer writes in the field and a comma; thus, invalid html FYI).
Copy linkTweet thisAlerts:
@repeater09authorDec 03.2011 — Ok, I got it to work....criterion9 was right....it was sending as valid HTML thus the HTML headers could not properly display it thus.....nothing shows up....thanks for that....now how could I redirect to another page after going to the mailform.php page?
×

Success!

Help @repeater09 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 6.15,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...