Can someone please tell me how to fix this script so the form info is sent to the correct email (i.e., my email….lets assume my email is username@mydomain.net). I would like the email to show the user’s email addrress who sent to to me as well.
<?php
$name = $_POST['fldName'];
$email = $_POST['fldEmail'];
$phone = $_POST['fldPhone'];
$comments = $_POST['fldComments'];
$isFormValid = false;
if (strlen($name) && strlen($email) && strlen($phone) && strlen($comments)) $isFormValid = true;
if ($isFormValid)
{
$to = 'username@mydomain.net';
$subject = 'Contact Us Form Comments';
$message = 'Name: '.$name."\r\n".'Email: '.$email."\r\n".'Comments: '.$comments;
$headers = 'From: username@domain.net' . "\r\n"
. 'Reply-To: username@mydomain.net' . "\r\n";
mail($to, $subject, $message, $headers);
header("location: thankyou.html");
}
else
{
echo "Please fill in the required fields";
}
?>
instead of using native PHP mail() to do everything by yourself, it is better off you use some useful library like swift mailer, which makes it very easier for you to send mail without having to worry about the inner workings.
for example to send a mail in swift mailer all you need to do is.
you can find more information about swift mailer in there official website http://swiftmailer.org/