Hi, I have a form with a field for an email address to be filled in and sent using a php script. i need help with the following

1: i want the an email to be sent to the email address that the user has just typed into the form field.

2: I want to style the resulting message that they receive, to have some text in red, or bold etc, so its not just black text in an email.

The thing is everything I have tried so far just shows the styling code in the email that is sent. here's my code from the sendform.php
<?php
$email = $_REQUEST;
$message = "Thank you for applying for an INSTANT DISCOUNT CODE. \n\n 1a2b3c4d5e \n\n is your discount code, please type it using lowercase letters at the checkout \n\n\n Thanks The Team";

mail ("me@myemailaddress.co.uk", "$email", "$message", "from: the team");

header ("location: http://www.mydomain.co.uk/confirmation.htm");

//mail($to, $subject, $message, $headers);
?>
any help appreciated.

Kevin

Recommended Answers

All 3 Replies

MIME html email eg

<?php
$email = $_REQUEST['email'];
$headers .= "Reply-To: me@myemailaddress.co.uk\r\n";
$headers .= "Return-Path: me@myemailaddress.co.uk\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><head><style='text/css'>.red {color:red;}</style></head><body>";
$message .= "<h1> This is a test </h1>";
$message .= "Thank you for applying for an INSTANT DISCOUNT CODE. \n\n <span class='red'> 1a2b3c4d5e</span> \n\n is your discount code, please type it using lowercase letters at the checkout \n\n\n Thanks The Team";
$message .= "</body></html>";
$email = $_REQUEST['email'];
mail ("me@myemailaddress.co.uk", "$email", "$headers $message", "from: the team");
if ( mail($to,$subject,$message,$headers) ) { header ("location: http://www.mydomain.co.uk/confirmation.htm"); } 
else { header ("location: http://www.mydomain.co.uk/failed.htm");  }
?>

the code highlighting is done by [code=language] in this case code=php [/code] tags, makes for easier reading, debugging

sample only, did not check the code, pulled out of my *****
look at php.net mail for mime mail proper formatting

Thanks for getting back to me so quickly!
I tried using your code but I could still see the html tags in the final email.

Also I only want to send the email back to the email address that the user has put in the html form. So as soon as they put their email address in and press send, the email will get sent to them, with a short message, something like:-

<h1>Thanks you for applying for an instant discount code</h1>
<p class="red_text">This is your code 1a2b3c4d</p>

<h2>The Team<h2>

Thanks
Kevin

sample only, did not check the code pulled out of my *****
look at look at php.net mail for mime mail proper formatting

thats why the above was written and a link to php html mail was given, so you can find the correct code for your exact application
html mail is at the bottom half of the page

MUST include the mime type headers to use html mail or else it is plain text

MUST include the other headers, or your mail will get bounced from any server in the route with a spam catcher

and perhaps, fwrite the email address and passcode given to a csv text file on your server to trace how many people have gained proper access to the discount

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.