SteveH
01-29-2010, 10:51 AM
Hello
I hav these two files on a Linux server which insists on smtp authentication. I get a 'your message has been sent' message, but the email never arrives.
This is the HTML form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Form2Mail</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<div>
<center>
<form method="post" enctype="multipart/form-data" name="send" action="formprocess.php">
<table border="0" bgcolor="#ececec" cellspacing="5">
<tr><td>Name</td><td><input type="text" size="30" name="name"></td></tr>
<tr><td>Email address</td><td><input type="text" size="30" name="emailaddr"></td></tr>
<tr><td>Message</td><td><textarea name="message" rows="6" cols="30"></textarea></td></tr>
<tr><td>Attachment</td><td><input type="file" name="attachment" size="50" /><br /></td></tr>
<tr><td> </td><td><input type="submit" value="Send"></td></tr>
</table>
</form>
</center>
</div>
</body>
</html>
And this is the PHP script behind it:
<?php
$fileatt = ""; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = ""; // Filename that will be used for the file as the attachment
$email_from = ""; // Who the email is from
$email_subject = ""; // The Subject of the email
$email_txt = ""; // Message that the email has in it
$email_to = "myEmail@yahoo.com"; // Who the email is to
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";
$data = chunk_split(base64_encode($data));
$email_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";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
echo "The file was successfully sent!";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
$host = "smtp.mySite.com";
$username = "info@mySite.com";
$password = "myPassword";
?>
Any help appreciated.
Thanks.
Steve
I hav these two files on a Linux server which insists on smtp authentication. I get a 'your message has been sent' message, but the email never arrives.
This is the HTML form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Form2Mail</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<div>
<center>
<form method="post" enctype="multipart/form-data" name="send" action="formprocess.php">
<table border="0" bgcolor="#ececec" cellspacing="5">
<tr><td>Name</td><td><input type="text" size="30" name="name"></td></tr>
<tr><td>Email address</td><td><input type="text" size="30" name="emailaddr"></td></tr>
<tr><td>Message</td><td><textarea name="message" rows="6" cols="30"></textarea></td></tr>
<tr><td>Attachment</td><td><input type="file" name="attachment" size="50" /><br /></td></tr>
<tr><td> </td><td><input type="submit" value="Send"></td></tr>
</table>
</form>
</center>
</div>
</body>
</html>
And this is the PHP script behind it:
<?php
$fileatt = ""; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = ""; // Filename that will be used for the file as the attachment
$email_from = ""; // Who the email is from
$email_subject = ""; // The Subject of the email
$email_txt = ""; // Message that the email has in it
$email_to = "myEmail@yahoo.com"; // Who the email is to
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";
$data = chunk_split(base64_encode($data));
$email_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";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
echo "The file was successfully sent!";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
$host = "smtp.mySite.com";
$username = "info@mySite.com";
$password = "myPassword";
?>
Any help appreciated.
Thanks.
Steve