Jump to content

 in mail()


chrisboots

Recommended Posts

Hi all


using the mail function on my works website, it gets the info from a form and mails it to us but instead of getting £(price) we get £(price).


my boss is being fussy and wants the  gone. please can someone help me figure this out, code below 

<?php
if(isset($_POST['email'])) {
     
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "bookings@pennycarhire.co.uk";
    $email_subject = "Returning Customer Booking Request";
    $thankyou = "thankyou.html"; // thank you page 
	
     
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
     
    // validation expected data exists
    if(!isset($_POST['colect2']) ||
        !isset($_POST['coltime2']) ||
        !isset($_POST['email']) ||
        !isset($_POST['retur2']) ||
        !isset($_POST['rettime2'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }
	
	
     
    $colect = $_POST['colect2']; // required
    $ctime = $_POST['coltime2']; // required
    $email_from = $_POST['email']; // required
    $return = $_POST['retur2']; // not required
    $rtime = $_POST['rettime2']; // required
	$car = $_POST['cartype']; // required
	$days = $_POST['days2']; // required
	$price = $_POST['price2']; // required
	$waiv = $_POST['wavco']; // required
	$toprice = $_POST['tocost']; // required
	$name = $_POST['name']; // required
	$dd = $_POST['DD']; // required
	$mm = $_POST['MM']; // required
	$yy = $_POST['YY']; // required
	$liheld = $_POST['liheld']; // required
	$lipart = $_POST['lipart']; // required
	$claim = $_POST['claim']; // required
	$phone1 = $_POST['phone1']; // required
	$qorc = $_POST['qorc'];
	
	$find[] = 'Â';
	$replace[] = '';
	$title = str_replace($find, $replace, $title);
    
	$error_message = "";
 
    
  if(strlen($rtime) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
	
	

	 {$email_message .= "Name: ".clean_string($name)."\n\n";
	 
	 $email_message .= "Car Type: ".clean_string($car)."\n\n";
	 
	 $email_message .= "Collect on: ".clean_string($colect)."\n\n";
    
	$email_message .= "At: ".clean_string($ctime)."\n\n";
    
	$email_message .= "Return on: ".clean_string($return)."\n\n";
   
    $email_message .= "At: ".clean_string($rtime)."\n\n";
	
	
	
	$email_message .= "Days: ".clean_string($days)."\n\n";
	
	$email_message .= "Inclusive Price: ".clean_string($price)."\n\n";
	
	$email_message .= "Waiver Ammount (If Blank No Waiver): ".clean_string($waiv)."\n\n";
	
	$email_message .= "Total Cost: ".clean_string($toprice)."\n\n";
	
	$email_message .= "Email: ".clean_string($email_from)."\n\n";
	
	
	
    $email_message .= "Dob: ".clean_string($dd)."/".clean_string($mm)."/".clean_string($yy)."\n\n";
	
	$email_message .= "Contact Number: ".clean_string($phone1)."\n\n";
	
	$email_message .= "Bring both parts of licence (if no they have aggreed £3 charge): ".clean_string($lipart). "\n\n";
	
	$email_message .= "Claims Or Accidents: ".clean_string($claim)."\n\n";
	
	$email_message .= "Questions/Comments: ".clean_string($qorc)."\n\n";
	
	}
	
	
	
	
  
	
	
     
     
// create email headers
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>
 
<!-- include your own success html here -->
 
<script>location.replace('<?php echo $thankyou;?>')</script>
 
<?php
}
?>
Link to comment
Share on other sites

Your list of $headers needs a Content-Type with charset=UTF-8. "But I have that already!" You did, but then you overwrote it on the very next line.

$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion()."\r\n" .
'Content-Type: text/html; charset=UTF-8'."\r\n";
Word of advice: don't try to do mail()ing by yourself. Get something like PHPMailer to do that because it will do a better job than you and for less effort.
Link to comment
Share on other sites

Basically the issue (probably) boils down to a mis-communication between character encoding vs. that symbol (e.g. the email client trying to use ISO-8859-1 encoded pound sign in a UTF-8 encoded page or visa versa).

 

1) Try using £ or £ instead of the actual symbol, eg:

 

$email_message .= "Bring both parts of licence (if no they have aggreed £3 charge): ".clean_string($lipart). "\n\n";
2) Also, you seem to have a typo in your $headers. You didn't .= the 2nd "From:" line, so it's overwriting your first "Content-Type:" line and so the charset isn't being specified.

 

3) sidenote: I notice in your $email_message, you end in \n\n instead of \r\n\r\n. This may or may not cause your email to show up without linebreaks, depending on what OS someone is viewing the email on.

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.