Forum Moderators: coopster
<?php
$mailto = 'alexa@example.com' ;
// $subject - set to the Subject line of the email, eg
//$subject= "Feedback Form" ;
$subject = "CONTACT FORM" ;
// the pages to be displayed, eg
//$formurl= "http://www.example.com/feedback.html" ;
//$errorurl= "http://www.example.com/error.html" ;
//$thankyouurl= "http://www.example.com/thankyou.html" ;
$formurl = "index.html" ;
$errorurl = "index.html" ;
$thankyouurl = "thankyou.html" ;
$attachment = file_get_contents($filename);
$uself = 0;
$email_is_required = 0;
$name_is_required = 0;
// -------------------- END OF CONFIGURABLE SECTION ---------------
$headers = "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"simple-boundary\"\n";
$headers .= "From: $from";
$Name = $_POST['Name'] ;
$Email = $_POST['Email'] ;
$Telephone = $_POST['Telephone'] ;
$Request = $_POST['Request'] ;
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['Email'])) {
header( "Location: $formurl" );
exit ;
}
if (($Email_is_required && (empty($Email) ¦¦ !ereg("@", $Email))) ¦¦ ($Name_is_required && empty($Name))) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $Name ) ¦¦ ereg( "[\r\n]", $Email ) ) {
header( "Location: $errorurl" );
exit ;
}
if (empty($Email)) {
$Email = $mailto ;
}
if (get_magic_quotes_gpc()) {
$Request = stripslashes( $Request );
}
$message = "\n--simple-boundary\n";
$message .= "Content-Type: text/plain\n\n";
$message .= "This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $Name\n" .
"Email of sender: $Email\n" .
"Question or Comments: $Request" .
"\n------------------------------------------------------------\n" ;
// Attachment part
$message .= "--simple-boundary\nContent-Type: text/plain\n";
$message .= "Content-Disposition: attachment;\n";
$message .= " filename=\"$filename\"\n\n";
$message .= "$attachment\n\n";
mail($to, "Your attachment", $message, $headers);
header( "Location: $thankyouurl" );
exit ;
?>
[edited by: eelixduppy at 7:59 am (utc) on Feb. 22, 2009]
[edit reason] exemplified [/edit]
<?php
function SendMail($to,$subject,$MessageBody,$from,$cc,$attachmentname,$attachmenttype)
{
$random_hash = md5(date('r', time()));
$headers = "From: $from\r\n";
if($cc!=null)
{
$headers .= "Cc: $cc";
}
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
if($attachmentname==null)
{
$attachment=null;
}
else
{
$attachment = chunk_split(base64_encode(file_get_contents($attachmentname)));
}
ob_start();
?>
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<? echo $MessageBody;?>
--PHP-alt-<?php echo $random_hash; ?>--
<? if($attachment!=null){ ?>
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: <? echo $attachmenttype?>; name=<? echo $attachmentname; ?>
Content-Transfer-Encoding: base64
Content-Disposition: attachment
<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
<?php
}
$message = ob_get_clean();
$mail_sent = @mail( $to, $subject, $message, $headers );
if($mail_sent)
{
return true;
}
else
{
return false;
}
}
#edit bellow here and test
$MessageBody = 'This is the text included in Message Body';
if(SendMail('yourmail@domain.com','My Test Mail',$MessageBody,'MyTest',null,'yourattachement.ext','your attachement MIME eg.image/png')) {
echo 'Mail Sent';
}
else {
echo 'Not Done';
}
?>
Content-Type: multipart/mixed; boundary="PHP-mixed-8d585797103165262d373602f96dbddd"
--PHP-mixed-8d585797103165262d373602f96dbddd
Content-Type: multipart/alternative; boundary="PHP-alt-8d585797103165262d373602f96dbddd"
--PHP-alt-8d585797103165262d373602f96dbddd
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
This is the text included in Message Body
--PHP-alt-8d585797103165262d373602f96dbddd--
--PHP-mixed-8d585797103165262d373602f96dbddd
Content-Type: your attachement MIME eg.image/png; name=yourattachement.ext
Content-Transfer-Encoding: base64
Content-Disposition: attachment
--PHP-mixed-8d585797103165262d373602f96dbddd--
Warning: fopen(file.ext) [function.fopen]: failed to open stream: No such file or directory in /hermes/bosweb/web140/b1400/d5.dagostinohair/public_html/blackrhino/diction/test2.php on line 20
Warning: filesize() [function.filesize]: stat failed for file.ext in /hermes/bosweb/web140/b1400/d5.dagostinohair/public_html/blackrhino/diction/test2.php on line 21
Warning: fread(): supplied argument is not a valid stream resource in /hermes/bosweb/web140/b1400/d5.dagostinohair/public_html/blackrhino/diction/test2.php on line 21
Warning: fclose(): supplied argument is not a valid stream resource in /hermes/bosweb/web140/b1400/d5.dagostinohair/public_html/blackrhino/diction/test2.php on line 22
these were the error messages I received and below is the code I used.. This is extremely important to get done. Sorry!
<?php
// array with filenames to be sent as attachment
$files = array("file.ext");
// email fields: to, from, subject, and so on
$to = "email@example.com";
$from = "name";
$subject ="TEST";
$message = "My message";
$headers = "From: $from";
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$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" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
// preparing attachments
for($x=0;$x<count($files);$x++){
$file = fopen($files[$x],"rb");
$data = fread($file,filesize($files[$x]));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
}
// send
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>mail sent to $to!</p>";
} else {
echo "<p>mail could not be sent!</p>";
}
?>
[edited by: eelixduppy at 9:22 pm (utc) on Feb. 22, 2009]
[edit reason] specifics [/edit]
check the bellow
SendMail('email@example.com','My Test Mail','Test Message Body','MyTest',null,'image.png','image/png');
[edited by: eelixduppy at 6:58 am (utc) on Feb. 25, 2009]
[edit reason] specifics [/edit]