Jump to content

.London Domains - £4
Photo

Mail form not doing what I want!


  • Please log in to reply
1 reply to this topic

#1 juicylemons

juicylemons
  • Member
  • Newbie
  • 9 posts

Posted 30 November 2018 - 11:46

Hi All,

 

I have a mail form that I am trying to get to send a html email so that I can add some really simple formatting (different font colour and bold). I just cant seem to work out why I cant get the html output to work?? I am getting an email still with the html tags I have used as if the php i have written is not sending with html enabled. This is the code - please can some someone help me fix it as I have been trying to solve this for weeks and I am ready to put my head in an oven....

<?php

if(isset($_POST['email'])) {


// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "dan@elastothane.com";
$email_subject = "Order - Online submission";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";




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['name']) ||
!isset($_POST['company_name']) ||
!isset($_POST['email']) ||
!isset($_POST['purchase_order']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}






$name = $_POST['name']; // required
$company_name = $_POST['company_name']; // required
$email_from = $_POST['email']; // required
$purchase_order = $_POST['purchase_order']; // not required
$comments = $_POST['comments']; // not required
$product1=$_POST['product1'];
$kit1=$_POST['kit1'];
$colour1=$_POST['colour1'];
$quantity1=$_POST['quantity1'];


$product2=$_POST['product2'];
$kit2=$_POST['kit2'];
$colour2=$_POST['colour2'];
$quantity2=$_POST['quantity2'];


$product3=$_POST['product3'];
$kit3=$_POST['kit3'];
$colour3=$_POST['colour3'];
$quantity3=$_POST['quantity3'];




$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';


if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}


$string_exp = "/^[A-Za-z0-9 .'-]+$/";


if(!preg_match($string_exp,$name)) {
$error_message .= 'The name you entered does not appear to be valid.<br />';
}


if(!preg_match($string_exp,$company_name)) {
$error_message .= 'The company name you entered does not appear to be valid.<br />';
}




if(strlen($comments) < 0) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';


}


if(strlen($error_message) > 0) {
died($error_message);
}


$email_message = "Hello Charlotte & team.\n\n Please call (07920 473881) or email me to obtain our ref number before adding this order. Order details are as follows:  \n\n";




function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}




$email_message = "<html><body>";
$email_message .= "<b>name: </b>".clean_string($name)."\n";
$email_message .= "Company Name: ".clean_string($company_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Purchase order: ".clean_string($purchase_order)."\n";
$email_message .= "Delivery address: ".clean_string($comments)."\n\n";
$email_message .= "First product required: ".clean_string($product1)."\n";
$email_message .= "Pack size: ".clean_string($kit1)."\n";
$email_message .= "Colour required: ".clean_string($colour1)."\n";
$email_message .= "Quantity required: ".clean_string($quantity1)."\n\n";
$email_message .= "Second product required: ".clean_string($product2)."\n";
$email_message .= "Size of pack: ".clean_string($kit2)."\n";
$email_message .= "Colour required: ".clean_string($colour2)."\n";
$email_message .= "Quantity required: ".clean_string($quantity2)."\n\n";
$email_message .= "Third product required: ".clean_string($product3)."\n";
$email_message .= "Pack size: ".clean_string($kit3)."\n";
$email_message .= "Colour required: ".clean_string($colour3)."\n";
$email_message .= "Quantity required: ".clean_string($quantity3)."\n";






// create email headers
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers = 'From: '.$email_from."\r\n".






'Reply-To: '.$email_from."\r\n" .
'Cc: dan@elastothane.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);


?>


'<script>window.location.href = "http://www.elastothane.com/done2.htm";</script>';


<?php


}
?>

Edited by Renaissance-Design, 30 November 2018 - 12:13.
Code formatting, please

  • 0

#2 Renaissance-Design

Renaissance-Design
  • Global Mod
  • Code Poet
  • 1,577 posts

Posted 30 November 2018 - 13:51

I don't see anything obviously wrong there, aside from the fact that you seem to be duplicating the MIME-Version and Content-Type headers. Are you able to receive HTML email from other sources?

 

I've removed your duplicate topic. While the forum can be a little dead at times, the correct response is not to further reduce the quality by spamming posts in places they don't belong.


  • 0

Chris Cox is a freelance web designer & developer based in Bridgend, South Wales. You should definitely follow @RenaissDesign on Twitter.

Was this post helpful? Buy me a beer.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users