Jump to content

My PHP form doesn't work


joshgarrod

Recommended Posts

Hello all,

 

I have a PHP form but it doesn't seem to work. Everything looks right to me and when you submit the it goes to my success page, but I receive no email in my inbox. any ideas please?

 

PHP:

<?php
// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$EmailTo = "[email protected]";
$Subject = "subject line";
$Name = Trim(stripslashes($_POST['Name'])); 
$Articletitle = Trim(stripslashes($_POST['Articletitle'])); 
$Articletext = Trim(stripslashes($_POST['Articletext'])); 

// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Article title: ";
$Body .= $Articletitle;
$Body .= "\n";
$Body .= "Article text: ";
$Body .= $Articletext;
$Body .= "\n";
$Body .= "Email from: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "blah blah";
$Body .= "\n";

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

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

 

HTML:

<form method="POST" action="contact.php">
Fields marked (*) are required
<p>Email From:* <br>
<input type="text" name="EmailFrom">
<p>Name:*<br>
<input type="text" name="Name">
<p>Article title:*<br>
<input type="text" name="Articletitle">
<p>Article text:*<br>
<textarea name="Articletext" cols="100" rows="20"></textarea>
<p><input type="submit" name="submit" value="Submit">
</form>

Link to comment
https://forums.phpfreaks.com/topic/98245-my-php-form-doesnt-work/
Share on other sites

try using these headers for your mail function:

 

  $headers  = "MIME-Version: 1.0\r\n";

  $headers .= "Content-type: text/html; charset=utf-8\r\n";

  $headers .= "From: NAME <" .  $toOne . ">\r\n";

 

mail($to, $subject, $body, $headers);

 

 

You will have better success using headers to achieve what you want

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.