Forums
This topic is locked
Image Attachment Problem
Posted 05 Mar 2008 16:56:30
1
has voted
05 Mar 2008 16:56:30 Veli Muhlarhi posted:
GreetingsI have a serious problem, i would like my php script to accept image attachments so they can be sent to a specific email address. The other field are obtained once the form has but submitted.
SOMEBODY PLEASE PLEASE PLEASE HELP ME I'M RUNNING OUT OF TIME. PLEASE TELL ME WHATS WRONG AND WHAT CAN BE DONE TO FIX/ SORTOUT THE PROBLEM
HERE IS THE SCRIPT:
<?php
$firstname = $_POST['FirstName'];
$lastname = $_POST['LastName'];
$email = $_POST['EmailAddress'];
$number = $_POST['ContactNumber'];
$NameOfAdvertisedItem = $_POST['NameOfAdvertisedItem'];
$Genres = $_POST['Genres'];
$Format = $_POST['Format'];
function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r"
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use diff. tyoes here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
if (mail($mailto, $subject, "", $header)) {
echo = "mail send ... OK"; // or use booleans here
} else {
echo = "mail send ... ERROR!";
}
}
// how to use
$my_file = "somefile.zip";
$my_path = $_SERVER['DOCUMENT_ROOT']."/Main/Sign_up/upload/";
$my_name = "Olaf Lederer";
$my_mail = " ";
$my_replyto = " ";
$my_subject = "This is a mail with attachment for ads.";
$my_message = "Hallo,\r\ndo you like this script? I hope it will help.\r\n\r\ngr. Olaf";
mail_attachment($my_file, $my_path, " ", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
$Picture2 = $_POST['Picture2'];
$Picture4 = $_POST['Picture4'];
$video = $_POST['video'];
$ShortDescription = $_POST['ShortDescription'];
$country = $_POST['country'];
$Province = $_POST['Province'];
$CityTown = $_POST['CityTown'];
$Duration = $_POST['Duration'];
$tnc_agree = $_POST['tnc_agree'];
$to = "ContiAds! < >";
$subject = "RE: New ContiAds SignUp!";
$body = "<html>".
"<head>".
"<title>Contact Request</title>".
"<style type='text/css'>".
"body,td,th {".
"font-family: Geneva, Arial, Helvetica, sans-serif;".
"font-size: 12px;".
"}".
".style1 {font-size: 24px}".
"</style></head>".
"<body>".
"<p align='center' class='style1'>ContiAds New Signup</p>".
"<table width='498' border='0' align='center' cellpadding='5' cellspacing='0'>".
"<tr>".
"<td colspan='2' valign='top' bgcolor='#333333' height='2px'></td>".
"</tr>".
"<tr>".
"<td width='104' valign='top'>Full Name:</td>".
"<td width='374'>".$firstname." ".$lastname."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Contact Number:</td>".
"<td>".$number."</td>".
"</tr>".
"<tr>".
"<td valign='top'>E-mail Address:</td>".
"<td>".$email."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Number of Advertised Items:</td>".
"<td>".$NameOfAdvertisedItem."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Genres:</td>".
"<td>".$Genres."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Format:</td>".
"<td>".$Format."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Short Description:</td>".
"<td>".$ShortDescription."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Country:</td>".
"<td>".$country."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Province:</td>".
"<td>".$Province."</td>".
"</tr>".
"<tr>".
"<td valign='top'>City / Town:</td>".
"<td>".$CityTown."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Duration:</td>".
"<td>".$Duration."</td>".
"</tr>".
"<tr>".
"<td colspan='2' valign='top' bgcolor='#333333' height='2px'></td>".
"</tr>".
"</table>".
"</body>".
"</html>";
//Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $email . "\r\n";
//$headers .= 'Cc: ' . "\r\n";
if (mail($to, $subject, $body, $headers)) {
?>
<script language="javascript" type="text/javascript">
location.replace("Sign%20Up%20Success.htm"
</script>
<?php
} else {
?>
<script language="javascript" type="text/javascript">
location.replace("Sign%20Up%20Failure.htm"
</script>
<?php
}
?>