I am new to PHP, but, I have a simple contact form that is sending to my email. Everything works as expected except the $message variable is not displaying.
The php is processing the request and sending the website viewer to the thank you page, viewer is also getting confirmation email, and I am receiving the email with all requested variables except the $message data.
The variables are consolidated into $totalmessage due to the mail() function limits.
As I said, I am new to php, but appreciate your help.
PHP code:
<?php
$to = "me@mywebsite.com";
$subject = "Inquiry";
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$phone = $_REQUEST['phone'] ;
if (isset($_POST['interest']) && $_POST['interest']!= 'none'){
if (is_array($_POST['interest'])){
$interest = implode(" ", $_POST['interest']); // format your array for use
} else {
$interest = $_POST['interest']; // no array -> print single value
}
}
$method = $_REQUEST['method' ] ;
$message = $_GET['message'] ;
$totalmessage = "
Name: $name \n
Email: $email \n
Phone: $phone \n
Interest: $interest \n
Method: $method \n
Message: $message \n ";
$headers = "From: $email";
$sent = mail($to, $subject, $totalmessage, $headers);
if($sent)
header( "Location: /thankyou.html" );
else
print "We encountered an error sending your mail";
?>
HTML code:
<div class="row">
<br><label for="message"> Message:</label><br/>
<textarea name="message" rows="20" cols="20" id="message"></textarea>
</div>
Email Output:
Name: bob
Email: bob@gmail.com
Phone: 123-456-7890
Interest: research
Method: email
Message: <===should have message text
You shouldnt use the GET variable for sending the message.
The URL can only send 255 letters! So the best is to send it with POST.
and in ur php: