RE: What is wrong with this function please?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I take it there are no errors... And your using windows... Sending to
exchange... I guess with seeing what you posted, I would start by echoing
out what you have in  $to, $subject, $msg, $headers. Are there any errors in
Exchange logs? Do you see the message coming into Exchange queue?

Jake


> -----Original Message-----
> From: Robin Wilson [mailto:robinwilson@xxxxxxxxxxxx] 
> Sent: Friday, March 23, 2007 9:53 PM
> To: php-general@xxxxxxxxxxxxx
> Subject:  What is wrong with this function please?
> 
> Hello
> 
> I'm trying to do a function that emails users and sends an 
> attachment. But I 
> think something is in the wrong order or something as when I send it 
> Exchange discards it.
> 
> This is the function which I have put together from various sources:
> 
> I would really appreciate any help as I have been up half the 
> night and got 
> nowhere!
> Thanks
> Robin
> 
> function sendMail($to, $toName, $from, $fromName, $subject, $message, 
> $uploadfile, $fileName, $fileType, $fileSize) {
>  $eol="\r\n";
>   $mime_boundary=md5(time());
> 
>   # Common Headers
>   $headers .= 'From: '. $fromName .' <'. $from .'>'.$eol;
>   $headers .= 'Reply-To: '. $toName .' <'. $to .'>'.$eol;
>   $headers .= 'Return-Path: '. $fromName.' <'. $from 
> .'>'.$eol;    // these 
> two to set reply address
>   $headers .= "Message-ID: 
> <".$mime_boundary."@".$_SERVER['SERVER_NAME'].">".$eol;
>   $headers .= "X-Mailer: PHP v".phpversion().$eol;          
> // These two to 
> help avoid spam-filters
> 
>   # Boundry for marking the split & Multitype Headers
>   $headers .= 'MIME-Version: 1.0'.$eol;
>   $headers .= "Content-Type: multipart/related; 
> boundary=\"".$mime_boundary."\"".$eol;
> 
>  $msg = " ";
> 
>  if ($uploadfile != "") {
>   # File for Attachment
>        $file_name = substr($uploadfile, (strrpos($uploadfile, 
> "/")+1));
> 
>        $handle=fopen($uploadfile, 'rb');
>        $f_contents=fread($handle, $fileSize);
>        $f_contents=chunk_split(base64_encode($f_contents));   
>  //Encode The 
> Data For Transition using base64_encode();
>        fclose($handle);
> 
>        # Attachment
>        $msg .= "--".$mime_boundary.$eol;
>        $msg .= "Content-Type: ".$fileType."; 
> name=\"".$file_name."\"".$eol;
>        $msg .= "Content-Transfer-Encoding: base64".$eol;
>        $msg .= "Content-Disposition: attachment; 
> filename=\"".$file_name."\"".$eol.$eol; // !! This line needs 
> TWO end of 
> lines !! IMPORTANT !!
>        $msg .= $f_contents.$eol.$eol;
>  }
> 
>  # Setup for text OR html
>    $msg .= "Content-Type: multipart/alternative".$eol;
> 
>    # Text Version
>    $msg .= "--".$mime_boundary.$eol;
>    $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
>    $msg .= "Content-Transfer-Encoding: 8bit".$eol;
>    $msg .= strip_tags(str_replace("<br>", "\n", $message)).$eol.$eol;
> 
>    # HTML Version
>    $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
>    $msg .= "Content-Transfer-Encoding: 8bit".$eol;
>    $msg .= $message.$eol.$eol;
> 
>    # Finished
>    $msg .= "--".$mime_boundary."--".$eol.$eol;  // finish 
> with two eol's for 
> better security. see Injection.
> 
> 
>  // Mail it
>  mail($to, $subject, $msg, $headers);
> } 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> -- 
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.446 / Virus Database: 268.18.17/730 - Release 
> Date: 3/22/2007 7:44 AM
>  
> 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.17/730 - Release Date: 3/22/2007
7:44 AM
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux