Forum Moderators: coopster
<?php
$Name=$_POST["Name"];
$Address=$_POST["Address"];
$City=$_POST["City"];
$State=$_POST["State"];
$Zip=$_POST["Zip"];
$Phone=$_POST["Phone"];
$Cell=$_POST["Cell"];
$Fax=$_POST["Fax"];
$Email=$_POST["Email"];
$DogsName=$_POST["DogsName"];
$DogsAge=$_POST["DogsAge"];
$Breed=$_POST["Breed"];
$DogsWeight=$_POST["DogsWeight"];
$DogsSex=$_POST["DogsSex"];
$SpayedNeutered=$_POST["SpayedNeutered"];
$Medications=$_POST["Medications"];
$Diet=$_POST["Diet"];
$Exercise=$_POST["Exercise"];
$Story=$_POST["Story"];
$Diabetes=$_POST["Diabetes"];
$KidneyLiver=$_POST["KidneyLiver"];
$FoodAllergies=$_POST["FoodAllergies"];
$HeartDisease=$_POST["HeartDisease"];
$Other=$_POST["Other"];
$entrant = sprintf("Please Enter Us Into the Healthiest Hound Contest: %s\n\nName: %s\n\nAddress: %s %s\n\nPhone:%s\n\nCell Phone: %s\n\nEmail: %s\n",
$Name, $Address, $City, $State, $Zip, $Phone, $Cell, $Email);
$hound = sprintf("Description of Hound to Be Entered:\nName: %s, Age: %s, Breed: %s, Weight: %s, Sex: %s, Spayed/Neutered: %s\n\n\n",
$DogsName, $DogsAge, $Breed, $DogsWeight, $DogsSex, $SpayedNeutered);
$details = sprintf("Medications:\n\n%s\n\nDiet:\n\n%s\n\nExercise: %s\n\nStory: %s\n\n\n",
$Medications, $Diet, $Exercise, $Story);
$ailments = sprintf("Diabetes: %s\n\nKidney/Liver Disease: %s\n\nFood Allergies: %s\n\nHeart Disease: %s\n\nOther: %s\n\n",
$Diabetes, $KidneyLiver, $FoodAllergies, $HeartDisease, $Other);
$body1 = sprintf("%s\n%s\n%s\n%s\n",
$entrant, $hound, $details, $ailments);
$body2 = sprintf("Thank You For Applying to Our Curb Your Pouch Contest\nWe will get back with you in several working days\nHere is the info you sent us. Thanks Again!\n\n%s", $body1);
$to = "$Name <$Email>";
$from = "Info Curb Your Pouch <info@example.com>";
$subject = "Application Curb Your Pouch";
if ($_FILES["Picture1"]["error"] > 0)
{
echo "Return Code: " . $_FILES["Picture1"]["error"] . "<br />";
}
else
if (is_uploaded_file($_FILES['Picture1']['tmp_name']))
{
echo "Upload: " . $_FILES["Picture1"]["name"] . "<br />";
echo "Type: " . $_FILES["Picture1"]["type"] . "<br />";
echo "Size: " . ($_FILES["Picture1"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["Picture1"]["tmp_name"] . "<br />";
}
else
{
echo "File Not Uploaded: ";
echo "filename '". $_FILES['Picture1']['tmp_name'] . "'.";
}
if ($_FILES["Picture2"]["error"] > 0)
{
echo "Return Code: " . $_FILES["Picture2"]["error"] . "<br />";
}
else
if (is_uploaded_file($_FILES['Picture2']['tmp_name']))
{
echo "Upload: " . $_FILES["Picture2"]["name"] . "<br />";
echo "Type: " . $_FILES["Picture2"]["type"] . "<br />";
echo "Size: " . ($_FILES["Picture2"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["Picture2"]["tmp_name"] . "<br />";
}
else
{
echo "File Not Uploaded: ";
echo "filename '". $_FILES['Picture2']['tmp_name'] . "'.";
}
$headers = "From: $from\r\n";
$headers .= "Bcc: email@example.com";
$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" .
$body2 . "\n\n";
$fileatt = $_FILES["Picture1"]["tmp_name"];
$fileattname = "sideview.jpg";
$fileatttype = $_FILES["Picture1"]["type"];
$file = fopen( $fileatt, 'rb' );
$data = fread( $file, $_FILES["Picture1"]["size"]);
fclose($file);
$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";
unset($data);
unset($file);
unset($fileatt);
unset($fileatttype);
unset($fileattname);
$fileatt2 = $_FILES["Picture2"]["tmp_name"];
$fileatt2name = "topview.jpg";
$fileatt2type = $_FILES["Picture2"]["type"];
$file2 = fopen( $fileatt2, 'rb' );
$data2 = fread( $file2, $_FILES["Picture2"]["size"]);
fclose($file2);
$data2 = chunk_split(base64_encode($data2));
$message .= "Content-Type: {$fileatttype};\n" .
" name=\"{$fileattname}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data2 . "\n\n" .
"--{$mime_boundary}--\n";
unset($data2);
unset($file2);
unset($fileatt2);
unset($fileatt2type);
unset($fileatt2name);
if( mail( $to, $subject, $message, $headers ) )
echo "<p>The email was sent.</p>";
else
echo "<p>There was an error sending the mail.</p>";
?>
[edited by: eelixduppy at 10:12 pm (utc) on Sep. 23, 2008]
[edit reason] exemplified [/edit]
I use a class called htmlMimeMail, sends multipart attachments as well as both html plain text versions for those whose email clients don't [choose to] do html, and it supports smtp, which I prefer.
I've also had my eye on phpmailer at codeworx and xpertmailer at .com of the same name. I've downloaded the former but haven't had a chance to play with it much.
I'm all for reinventing the wheel if I can make it roll better but the class I use has served me well for a number of years now.
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->IsHTML(false);
$mail->Host = "mail.example.com";
$mail->From = "email@example.com";
$mail->FromName = 'Example Mailer';
$mail->FromName = "Theresa";
$mail->AddAddress("email@example.com","TestName");
$mail->WordWrap = 50;
//////$mail->AddAttachment("jpeg");
$mail->AddAttachment("'".$_FILES['uploadedfile']['name']."'");
$mail->AddAttachment("'".$_FILES['uploadedfile1']['name']."'");
$mail->IsHTML(true);
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML body";
$mail->AltBody = "This is the text-only body";
if(!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
?>
and here is my error
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in d:\web\example.com\www\phpmailer\class.phpmailer.php on line 45
Fatal error: Cannot instantiate non-existent class: phpmailer in d:\web\example.com\www\test1\mail.php on line 4
[edited by: eelixduppy at 12:37 am (utc) on Sep. 27, 2008]
[edit reason] exemplified [/edit]