Ave,
I'm facing a little problem.
I have this code which enables me to attach a file and send the file as an
attachment with the Mail.
What I need to do is slightly different.
Firstly, I want to send 2 files as attachment, and not one. Secondly, I
don't want the user to select & attach the file, I want the files to be
already attached in the script. I.e., 2 pre-determined, pre-attached files
should go along with the script.
Here's the code I am using thus far for attaching 1 file...
Can anyone suggest what I should do differently?
<?php
$allowtypes=array("zip", "rar", "txt", "doc", "jpg", "jpeg", "png", "gif",
"pdf");
$fromemail="[EMAIL PROTECTED]";
$fromname="myName";
$priority="3";
$allowattach="1";
$submitvalue=" Send Email ";
$resetvalue=" Reset Form ";
$defaultsubject="Some Subject";
$thanksmessage="Mail Sent Successfully";
function get_ext($key) {
return(strtolower(substr(strrchr($key, "."), 1)));
}
If($_POST['domail']) {
extract($_POST);
If($allowattach) {
$attachment=$_FILES['attachment']['tmp_name'];
$attachment_type=$_FILES['attachment']['type'];
}
If ($fname=="") {
$error = "1";
$error_text .= "You did not enter your name!<br />";
}
If ($emailto=="") {
$error = "1";
$error_text .= "You did not enter your email!<br />";
}
If ($emailto) {
If
(!eregi("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}\$",$emailto)
){
$error = "1";
$error_text .= "Invalid Email Address!<br />";
}
}
If($allowattach) {
foreach($allowtypes as $it) {
$types .="*.".$it.",";
}
If($attachment) {
$ext=get_ext($_FILES[attachment][name]);
If(!in_array($ext, $allowtypes)) {
$error = "1";
$error_text .= "Invalid extension for your attchment,
only ".$types." are allowed!<br />";
}
}
}
If($error=="1") {
$disperrors=$error_text;
} Else {
$headers = "From: ".$fromname." <".$fromemail.">\n";
$headers .= "Reply-To: ".$fromname." <".$fromemail.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;
boundary=\"MIME_BOUNDRY\"\n";
$headers .= "X-Sender: ".$_SERVER['REMOTE_ADDR']."\n";
$headers .= "X-Mailer: phMailerv1.3\n";
$headers .= "X-Priority: ".$priority."\n";
$headers .= "Return-Path: <".$emailto.">\n";
$headers .= "This is a multi-part message in MIME format.\n";
If($allowattach) {
If($attachment) {
[EMAIL PROTECTED]($attachment,"r");
[EMAIL PROTECTED]($fp, filesize($attachment));
[EMAIL PROTECTED](base64_encode($str));
}
}
$yourmessage = "The main body content";
$message = "--MIME_BOUNDRY\n";
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n";
$message .= "\n";
$message .= "$yourmessage";
$message .= "\n";
If($allowattach) {
If($attachment) {
$message .= "--MIME_BOUNDRY\n";
$message .= "Content-Type: application/octet-stream;
name=\"" . $_FILES['attachment']['name'] . "\"\n";
$message .= "Content-disposition: attachment\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "\n";
$message .= "$str\n";
$message .= "\n";
$message .= "--MIME_BOUNDRY--\n";
}
}
If(!mail($emailto,$emailsubject,$message,$headers)) {
exit("There has been an error, please contact the admin");
}
Echo("<div align=\"center\">".$thanksmessage."<br><a
href=index.php>Send Another Mail</a></div>");
exit();
}
}
function cp() {
Echo("...");
}
?>
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: medium;
}
.style4 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size:
x-small; }
-->
</style>
<span class="style1">Informed Sources Inc.</span><br>
<br>
<table width="650" border="0" cellspacing="0" cellpadding="0">
<form action="index.php" method="post" enctype="multipart/form-data"
name="drama">
<tr>
<td><span class="style4">First Name </span></td>
<td><span class="style4">:</span></td>
<td><input name="fname" type="text" id="fname" size="18">
<span class="style4">Last Name : </span>
<input name="lname" type="text" id="lname" size="18"></td>
</tr>
<tr>
<td><span class="style4">Email</span></td>
<td><span class="style4">:</span></td>
<td><input name="emailto" type="text" id="emailto" size="25"></td>
</tr>
<tr>
<td><span class="style4">Subject</span></td>
<td><span class="style4">:</span></td>
<td><input name="emailsubject" type="text" id="emailsubject"
size="40"></td>
</tr>
<tr>
<td><span class="style4">Attach</span></td>
<td><span class="style4">:</span></td>
<td><input name="attachment" type="file" id="attachment"></td>
</tr>
<tr>
<td colspan="3" align="right" valign="top"><input name="domail"
type="submit" id="domail" value="Send Email"></td>
</tr>
</form>
</table>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php