PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old March 13th, 2002, 11:11 AM
bellj bellj is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 bellj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Mail attachment problems

Can anyone out there work out why this code won't work with attachments? It'll post mail without attachments though.

Code:

$form = "
<form action="formmd.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="seenform" value="y">
<b>Email the Committee</b><br><br>

<table border=0 align=center cellpadding=0 cellspacing=0 marginwidth=0 marginheight=0 width=100% bgcolor=#996699>

<tr>
<td valign=top width=15%>Your Name: </td>
<input type="hidden" name="name" value="$user[1] $user[3]">
<td valign=top>$user[1] $user[3]</td>
</tr>

<tr>
<td valign=top>Your Email: </td>
<input type="hidden" name="email" value="$login@wycliffe.co.uk">
<td valign=top>$login@wycliffe.co.uk</td>
</tr>

<tr>
<td valign=top>Subject: </td>
<td valign=top><input type="text" name="subject" size="50" maxlength="50" value="$subject"></td>
</tr>

<tr>
<td valign=top>Message: </td>
<td valign=top><textarea name="message" rows="10" cols="45"></textarea></td>
</tr>

<tr>
<td valign=top>Picture:</td>
<td valign=top><input type=file name="attachment"></td>
</tr>

<tr>
<td colspan=2><input type="submit" style="background-color:transparent" value="Go Mail!"></td>
</tr>

</table>
</form>";


if ($seenform != "y") :
print($form);
else:

// check for valid file if attachment exists
if ($attachment_name && $attachment_size <= 0)
{
echo "Bad Attachment<br>";
}

// build message headers
$headers = "From: $name <$email>";

// if attachments exist
if($attachment_name || sizeof($amsg) > 0)
{

// create a MIME boundary string
$boundary = "=_" . md5(uniqid(time())) . "_=";
echo "$boundary";

// add MIME data to the message headers
$headers .= "MIME-Version:1.0n";
$headers .= "Content-Type: multipart/mixed; tboundary="$boundary"nn";

// start building a MIME message
// first part is always the message body
// encode as 7-bit text
$str = "--" . $boundary . "n";
$str .= "Content-Type: text/plain;tcharset="us-ascii"n";
$str .= "Content-Transfer-Encoding: 7bitn";
$str .= "$messagenn";

// if an uploaded attachment exists
// encode it and attach it as a MIME-encoded section
if ($attachment_name)
{
$fp = fopen($attachment, "rb");
$data = fread($fp, filesize($attachment));
$data = chunk_split(base64_encode($data));
fclose($fp);

// add the MIME data
$str .= "--" . $boundary . "n";
$str .= "Content-Type: " . $attachment_type . ";tname="" . $attachment_name . ""n";
$str .= "Content-Transfer-Encoding: base64n";
$str .= "Content-Disposition: attachment; tfilename="" . $attachment_name . ""nn";
$str .= $data . "n";
}

// all done
// add the final MIME boundary
$str .= "n--$boundary--n";

// assign the contents of $str to $body
// note that the original contents of $body will be lost
$message = $str;
}

// send out the message
$to = "yb@wycliffe.co.uk";

echo "To: $to";
echo "Subject: $subject";
echo "Final Message: $message";
echo "Final Headers: $headers";

$mail = mail($to, $subject, $message, $headers);

if(mail($to, $subject, $message, $headers))
{
$status = "Your message was successfully sent.";
}
else
{
$status = "An error occurred while sending your message.";
}

echo "$status<br>";
echo "$mail<br>";

endif;


The variable $user is read from a MYSQL database.
The variable $login is passed by the script which accesses this one.
The script is called formmd.php and calls itself once the submit button is clicked.

Thanks,

John

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Mail attachment problems


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway