I have the following PHP for sending a contact form:
<?php
if(isset($_POST['name']) && $_POST['email'] && $_POST['message'])
{
$companyname = $_POST['company-name'];
$name = $_POST['name'];
$email = $_POST['email'];
$areacode = $_POST['areacode'];
$phone = $_POST['phone'];
$country = $_POST['country'];
$message = $_POST['message'];
$to = "";
$subject = "New Message From: $name";
$message .= "$messege";
$headers = "From: $email";
$mailed = ( mail($to,$subject,$message,$headers) );
if( isset($_POST['ajax']))
$response = ($mailed) ? "1" : "0";
else
$response = ($mailed) ? "<h2>Success!</h2>" : "<h2>Error! There was a problem with sending.</h2>";
echo $response;
}
else
{
echo "Form data error!";
}
?>
in the "$message .= "$messege";
" I believe that what will be sent and viewed in the email client right? How can I add the area code, phone number and country as well as the message?
Ok i post the full code to wrap things up:
<?php
if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['message'])) {
$companyname = $_POST['company-name'];
$name = $_POST['name'];
$email = $_POST['email'];
$areacode = $_POST['areacode'];
$phone = $_POST['phone'];
$country = $_POST['country'];
$message = $_POST['message'];
$to = "support@loaidesign.co.uk";
$subject = "New Message From: $name";
$message = "$message
Area Code: $areacode
Phone Number: $phone
";
$headers = "From: $email";
$mailed = mail($to, $subject, $message, $headers);
if (isset($_POST['ajax'])) {
$response = ($mailed) ? "1" : "0";
} else {
$response = ($mailed) ? "<h2>Success!</h2>" : "<h2>Error! There was a problem with sending.</h2>";
}
echo $response;
} else {
echo "Form data error!";
}
Simply concat the message string with the info you want to add:
$message = "From: $name
$message
Phone: $phone, Country: $country, ...";
try this:
$headers = "From: " . strip_tags($_POST['email']) . "
";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "
";
$headers .= "CC: cc@example.com
";
$headers .= "MIME-Version: 1.0
";
$headers .= "Content-Type: text/html; charset=ISO-8859-1
";
// check http://css-tricks.com/sending-nice-html-email-with-php/
$new_message = $message;
$new_message .= $areacode.$phone;
$mailed = ( mail($to,$subject,$new_message,$headers) );