Jump to content

mail form.. not sending email but..


MSUK1

Recommended Posts

Okay, below is my mailer for a contact form i created. On one site it works fine. I even have it sending to several addresses from the othersite. However this site it doesnt want to work. PHP5 and mail() function is active.

 

<?php 
$Name = Trim(stripslashes($_POST['fullname'])); 
$EmailFrom = Trim(stripslashes($_POST['email'])); 
$EmailTo = "james@jd-creations.co.uk";
$Subject = Trim(stripslashes($_POST['subject'])); 
$answer = Trim(stripslashes($_POST['answer'])); 
$Comments = Trim(stripslashes($_POST['message'])); 
$Subject = "The Reason - Contact Us";

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

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $Comments;
$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=../contact/sent.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../contact/error.php\">";
}
?>

 

now i know it is wroking because it takes me to the sent.php page. not error.php

 

i think it worked once. now not at all.

 

Link to comment
Share on other sites

Allow me to reiterate:

 

The From: header should be a valid address on the sending server. It should not be an address a user fills in on the form, which is what it appears to be in your code.

 

If you need the address the user input in the form sent as a header so you can hit "Reply" in your mail client, I'd suggest you use it as a Reply-To: header. You should also be sanitizing all the user input to filter out any header injection attempts.

Link to comment
Share on other sites

Regarding header injection, you'll be better off googling 'prevent php email header injection' than having me try to explain it. In a nutshell, it involves checking for or stripping out all characters used to allow a spammer to insert more email addresses in the 'To:' header.

 

As far as your headers go, this should work.

 

 

$Headers = 'From: valid_address@your_domain.com' . "\r\n";$Headers .= "Reply-To: $EmailFrom\r\n";mail($EmailTo, $Subject, $Body, $Headers);

 

Link to comment
Share on other sites

all emails are being sent to matt@mattsolomon.co.uk

 

when that is not stated anywhere in the php..

 

<?php 
$Name = Trim(stripslashes($_POST['fullname'])); 
$EmailFrom = Trim(stripslashes($_POST['email'])); 
$EmailTo = "james@jd-creations.co.uk";
$Subject = Trim(stripslashes($_POST['subject'])); 
$answer = Trim(stripslashes($_POST['answer'])); 
$Comments = Trim(stripslashes($_POST['message'])); 
$Subject = "The Reason - Contact Us";
$Headers = 'From: james@jd-creations.co.uk' . "\r\n";
$Headers .= "Reply-To: $EmailFrom\r\n";

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

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $Comments;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, $Headers);

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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.