Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spaces in form email data 1

Status
Not open for further replies.

kylebellamy

Programmer
Jan 24, 2002
398
US
I came across this form and it's working fine as a contact form but the email I receive is all one long string of text.

I know that \n is the code for a new line but I can't figure where to put it in this. Either the form crashes or the entry disappears.

Code:
		$mail_recipient = "kyle.bellamy@gmail.com";
		$mail_subject = "Contact Me";
					$name = Trim(stripslashes($_REQUEST['name']));
					$email = Trim(stripslashes($_REQUEST['email']));
					$phone = Trim(stripslashes($_REQUEST['phone']));
					$message = Trim(stripslashes($_REQUEST['message']));
		$Body = "";
					$Body .= $name;
					$Body .= $email;
					$Body .= $phone;
					$Body .= $message;
									$headers  = 'MIME-Version: 1.0' . "\r\n";
									$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
									
			// send email 
$success = mail($mail_recipient, $mail_subject, $Body, $headers);
	if($success==true) 
	header('Location: /test4/index.html');
	else
	header('Location: /test4/index.html');

Any thoughts?

 
try this instead
Code:
$fields = array('name', 'email', 'phone', message');
$body = "<table>\n";
foreach ($fields as $field){
  $c = trim($_REQUEST[$field]);
  $body .= "<tr><td>$field :</td><td>$c </td></tr>\n";
}
$body .= "</table>";

$headers  = <<HEAD
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1

HEAD;
$mail_subject = 'Contact Request';
$success = mail($mail_recipient, $mail_subject, $body, $headers);
if($success){ 
    header('Location: /test4/index.html');
}  else {
    header('Location: /test4/index.html');
}
 
That worked really well, I had to fix a couple of small things as they were throwing errors but it took no time and works like a charm. Thanks!

There was a missing quote mark in the fields array and the header stuff didn't seem to work right so I reverted it to the code from the original program and that was that.

Final Code:
Code:
$fields = array('name', 'email', 'phone', 'message');
$body = "<table>\n";
foreach ($fields as $field){
  $c = trim($_REQUEST[$field]);
  $body .= "<tr><td>$field :</td><td>$c </td></tr>\n";
}
$body .= "</table>";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$mail_subject = 'Contact Request';
$success = mail($mail_recipient, $mail_subject, $body, $headers);
if($success){ 
    header('Location: /test4/index.html');
}  else {
    header('Location: /test4/index.html');
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top