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:
  #1  
Old March 13th, 2002, 12:11 PM
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!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek