tricky
tricky

Reputation: 5

Contact php mail page, only sending blank emails.

I am having problems with this contact page, emails are being sent fine but are blank! I cant seem to find a solution. I would of thought $_POST would need to be added, however, the web hosting companies says it is not necessary in this php script Thankyou for your time and help. Code snippet below.

<?php

$EmailFrom = "[email protected]";
$EmailTo = "[email protected]";
$Subject = "online form";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Message = Trim(stripslashes($_POST['Description of project']));
// validation
$validationOK=true;
if (!$validationOK) {
  echo "please check your details";
  header("Location: http://www.ibdengland.co.uk/thankyou.html");
  exit;
}

// prepare email body text

$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Description of project: ";
$Body .= $Message;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"1;URL=thankyou.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"1;URL=thankyou.html\">";
}
?>

Upvotes: 0

Views: 223

Answers (3)

Ripa Saha
Ripa Saha

Reputation: 2540

you have not use any header.

take help from here. and use it. I think it will help you.

post header like below

$headers = 'From:'.$EmailFrom . "\r\n" .
'Reply-To: '.$EmailFrom . "\r\n" .
'X-Mailer: PHP/' . phpversion();

then replace below

$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

with the below code

$success = mail($EmailTo, $Subject, $Body, $headers);

plz try this one. and inform me if this work or not.

Upvotes: 0

SDZ
SDZ

Reputation: 726

Try changing:

$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

To:

$success = mail($EmailTo, $Subject, $Body, "From: <".$EmailFrom.">");

Upvotes: 0

Akatosh
Akatosh

Reputation: 458

You forgot to add the headers.

Example:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: '. $EmailFrom . "\r\n" .
'X-Mailer: PHP/' . phpversion();

Upvotes: 1

Related Questions