Reputation: 349
So what I want to do is get the email they filled the forum in with and then send a message to that email they filled in here's what I have: it says its sent but I never get the message:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: My Contact Form';
$to = '$email';
$subject = 'Folio Message';
$body = "Hello";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<center><font color="lightgray"><p>Message Sent Successfully!</p><script type="text/javascript"> function leave() { window.location = "http://webdesign.about.com"; } setTimeout("leave()", 3000); </script></center>';
} else {
echo '<center><font color="lightgray"><p>Ah! Try again, please?</p></font></center>';
}
}
?>
So i have $to = '$email';
so by doing that it should read the email that was filled in right? Idk my PHP skills are weak
any idea's? or advice?
Thank you in advance kind people!
Upvotes: 0
Views: 67
Reputation: 965
Two things here:
From
header should contain valid mail address. E.g.
$from = 'From: [email protected]';
As others said fix the single quotes. You can just use $email
in mail
call like
mail ($email, $subject, $body, $from)
On a different note, consider sanitizing your POST parameters. Especially if your script is on publicly available site.
Upvotes: 0
Reputation: 164
Remove the apostrophes from the $to = '$email';
It should be $to = $email;
With the apostrophes, your $to variable is being set to the string "$email" and not the email that the user entered.
Upvotes: 1
Reputation: 44823
Drop the single quotes around $email
, so your code looks like this: $to = $email;
.
PHP evaluates content in single quotes as a literal string, without interpreting any variables. So, it is literally using the text $email
as the recipient's email address.
Upvotes: 0