Hi guys,
I have a form that currently writes to a database and sends the user to a specific page depending if they enter a unique email address. If its unique email they go to the coupon page, if its duplicate they redirect to the home page.
Now the client wants the user emailed an attachment in addition to redirecting to the coupon page.
I added some code from a tutorial but can't get it to work.. Can anyone look at this and point me in the right direction?
Ideally I'd like to have the user emailed an html confirmation to add a little style. But i assume this is more difficult so I'll wait on that one..
<?php
$con = mysql_connect("localhost","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("", $con);
$sql="INSERT INTO customers (FirstName, LastName, Email, Address, City, State, ZipCode)
VALUES
('$_POST[FirstName]','$_POST[LastName]','$_POST[Email]','$_POST[Address]','$_POST[City]','$_POST[state]','$_POST[Zip]')";
$result = mysql_query($sql,$con);
if (!$result){
die('<META HTTP-EQUIV="Refresh" CONTENT="0;URL=http://www.gatorscaters.com">');
}
$user = $_POST['Email'];
$usersubject = "Your $10 OFF Coupon for Gators Dockside";
$userheaders = "From: myemail\n";
$usermessage = "Your coupon is attached!";
$fileatt = "./10Coupon.jpg";
$fileatttype = "image/jpg";
$fileattname = "coupon.jpg";
$file = fopen($fileatt, 'rb');
$data = fread($file, filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . "boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" . "-{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\n" . "Content-Transfer-Encoding: 7bit\n\n" .
$message .= "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "–{$mime_boundary}\n" . "Content-Type: {$fileatttype};\n" . " name=\"{$fileattname}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileattname}\"\n" . "Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" . "-{$mime_boundary}-\n";
if(mail($user,$usersubject,$usermessage,$userheaders)) {
header ("location: http://www.gatorscaters.com/coupon.php");
}
mysql_close($con)
?>