PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Draco_03
Forum Regular
Posts: 577 Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada
Post
by Draco_03 » Mon Aug 16, 2004 12:26 pm
hi this is the code i'm using
Code: Select all
<?php
<?php
$piece = $_POST["piece"];
$email = $_POST["email"];
$serie = $_POST["serie"];
$msg = $_POST["msg"];
$warranty = $_POST["warranty"];
$destinataire = $_POST["destinataire"];
$boundary = "kader-12345";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary="$boundary"";
"--$boundary";
$headers .= "Content-Type: text/plain; charset="iso-8859-1"";
$headers .= "Content-Transfer-Encoding: 7bit";
$to = "$email";
$subject = "LPG Canada";
$message = "
<html>
<head>
<title>LPG Canada</title>
</head>
<body>
Hi i'm sending you\n\n
<br /><br />
<b>Piece :</b>$piece\n<br />
<b>serial number :</b> $serie\n<br />
<b>Warranty :</b> $warranty\n\n<br /><br />
<b>The reasons are the follwing :</b>\n<br />
$msg
</body>
</html>
";
"--$boundary";
$headers .= "Content-Type: image/jpeg; name="../file.txt"";
$headers .= "Content-Transfer-Encoding: base64";
$headers .= "Content-Disposition: attachment";
$headers .= "<base64 encoded data for the zendlogo.jpg image>";
"--$boundary--";
$headers .= "To: <$destinataire>\n";
$headers .= "From: <$email>\n";
if (mail($to, $subject, $message, $headers)) {
echo("<br /><br /><br /><center>Merci<br /><a href="../index.php">Accueil</a></center><br />");
} else {
echo("<center>Erreure, veuillez <a href="javascript:history.back();">cliquer ici</a> et recommencer</center>");
}
?>
I do not get any "text" displayed BUT i do have the "attachment" sign (in outlook) next to the email, but i don't see any file actually attached to it..
I don't know nothing about attachment in emails... but i didn't want to use phpmailer.
Any help would be appreciated
Last edited by
Draco_03 on Mon Aug 16, 2004 1:31 pm, edited 1 time in total.
Draco_03
Forum Regular
Posts: 577 Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada
Post
by Draco_03 » Mon Aug 16, 2004 12:29 pm
oh and i'm pretty sure my mistake is the $boundary thingy
Draco_03
Forum Regular
Posts: 577 Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada
Post
by Draco_03 » Mon Aug 16, 2004 1:48 pm
OK i tryed something else (tutorial over the net)
Code: Select all
<?php
$piece = $_POST["piece"];
$email = $_POST["email"];
$serie = $_POST["serie"];
$msg = $_POST["msg"];
$warranty = $_POST["warranty"];
$destinataire = $_POST["destinataire"];
/* recipients */
$to = "$email";
/* subject */
$subject = "LPG Canada";
// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary="{$mime_boundary}"";
// Add a multipart boundary above the plain message
$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" .
$msg . "\n\n";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name="{$fileatt_name}"\n" .
"Content-Disposition: attachment;\n" .
" filename="{$fileatt_name}"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
$headers .= "To: <$destinataire>\n";
$headers .= "From: <$email>\n";
if (mail($to, $subject, $message, $headers)) {
echo("<br /><br /><br /><center>Merci<br /><a href="../index.php">Accueil</a></center><br />");
} else {
echo("<center>Erreure, veuillez <a href="javascript:history.back();">cliquer ici</a> et recommencer</center>");
}
?>
My form is
Code: Select all
<form enctype="multipart/form-data" name="email" method="post" action="confirm/mailing_en_3.php">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="userfile" type="file" />
<table width="450" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top">Votre courriel</td>
<td align="left" valign="top"><input name="email" type="text" /></td>
</tr>
<tr>
<td align="left" valign="top">Destinataire </td>
<td align="left" valign="top"><input name="destinataire" type="text" /></td>
</tr>
<tr>
<td align="left" valign="top">Pi&egrave;ce</td>
<td align="left" valign="top"><input name="piece" type="text" /></td>
</tr>
<tr>
<td align="left" valign="top"># de s&eacute;rie</td>
<td align="left" valign="top"><input name="serie" type="text" /></td>
</tr>
<tr>
<td align="left" valign="top">Warranty<br /><br /></td>
<td align="left" valign="top"><input name="warranty" type="radio" value="yes" />yes
<input name="warranty" type="radio" value="no" />no<br /><br /></td>
</tr>
<tr>
<td align="left" valign="top">Message</td>
<td align="left" valign="top"><textarea name="msg" cols="30"></textarea></td>
</tr>
</table>
<br />
<br />
<input type="submit" value="Soumettre" />
</form>