Jump to content

[SOLVED] This will probably be easy for you guys


subminor

Recommended Posts

Hey all,

 

I'm trying to get my form handler to work. anyone have an answer as to why Im not?

 

I know that the $from email ad is recieving an email, and the $to email doesnt seem to be.

also it doesnt redirect and the 'else' is always printed.

 

thanks.

 

PHP code:

 

 

  <?php

$to = $_REQUEST['[email protected]'] ;

$from = $_REQUEST['email'] ;

$name = $_REQUEST['name'] ;

$headers = "From: $from";

$subject = "Online Enquiry";

 

$fields = array();

$fields{"name"} = "Name";

$fields{"email"} = "Email";

$fields{"home_tel"} = "Phone";

$fields{"mob_tel"} = "Mobile";

$fields{"Message"} = "Message";

 

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

 

$subject2 = "Thank you for contacting us";

$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.mysite.com";

 

if($from == '') {print "You have not entered an email, please go back and try again";}

else {

if($name == '') {print "You have not entered a name, please go back and try again";}

else {

$send = mail($to, $subject, $body);

$send2 = mail($from, $subject2, $autoreply);

if($send)

header("Location: http://www.google.com");

else

{print "We encountered an error sending your mail, please notify [email protected]"; }

}

}

?>

 

fixed script;

 

<?php

$to = '[email protected]';
$from = $_REQUEST['email'];
$name = $_REQUEST['name'];
$subject = "Online Enquiry";

$fields = array();
$fields["name"] = "Name";
$fields["email"] = "Email";
$fields["home_tel"] = "Phone";
$fields["mob_tel"] = "Mobile";
$fields["Message"] = "Message";

$body = "We have received the following information:\n\n";

foreach($fields as $a => $b) {
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}

$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.mysite.com";

if($from == '') {
print "You have not entered an email, please go back and try again";
} else {
if($name == '') {
	print "You have not entered a name, please go back and try again";
} else {
	$send = mail($to, $subject, $body);
	$send2 = mail($from, $subject2, $autoreply);
	if($send) {
		header("Location: http://www.google.com");
		exit;
	} else {
		print "We encountered an error sending your mail, please notify [email protected]";
	}
}
}
?> 

Read the error :), you printed to screen before attempting to send a header (headers are already sent by then)

 

change this chunk;

 

<?php
if($from == '') {
   print "You have not entered an email, please go back and try again";
} else {
   if($name == '') {
      print "You have not entered a name, please go back and try again";
   } else {
      $send = mail($to, $subject, $body);
      $send2 = mail($from, $subject2, $autoreply);
      if($send) {
         header("Location: http://www.google.com");
         exit;
      } else {
         print "We encountered an error sending your mail, please notify [email protected]";
      }
   }
}

 

to this;

 

<?php
if($from == '') {
   $error = "You have not entered an email, please go back and try again";
} elseif($name == '') {
   $error = "You have not entered a name, please go back and try again";
} else {
   $send = mail($to, $subject, $body);
   $send2 = mail($from, $subject2, $autoreply);
   if($send) {
      header("Location: http://www.google.com");
      exit;
   } else {
      $error = "We encountered an error sending your mail, please notify [email protected]";
   }
}
if(isset($error)) echo $error;

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.