Email Body is not being Sent

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

Post Reply
devarishi
Forum Contributor
Posts: 101
Joined: Fri Feb 05, 2010 7:15 pm

Email Body is not being Sent

Post by devarishi »

Hi,


Can anybody tell me why the Message-Body is not shown when email is recieved using the PHP Script as given below?

However, I can see the Attachment and the Subject Line properly. If I send an email to my Internal ID then everything is fine. But when the same email is sent to an external id such @someOtherCompany then the Message in the Body is not sent.

Can you show me how to seperate the $message varibale from being used in the $header part abd form it in HTML in a way that the Attachment part, and the subject part are not disturbed?

Code: Select all

 
<?php
 
#   .....................................................................................
#   This section attaches a specified .txt to the body of an email and sends it.
#   .....................................................................................
 
#   .....................................................................................
#           Attachment and Body of the Message Packing
#   .....................................................................................
 
 
    $message =  '<html><body><p>Hi,</p><br />' .
            '<p>Attached is the Report of the Media Tapes for the ' . $subjLine .
            '</p></body></html>';
 
 
    $file = "Uploads/" . $ticketID . ".txt";
    $file_size = filesize($file);
 
    $handle = fopen($file, "r");
    $content = fread($handle, $file_size);
    fclose($handle);
 
    $content = chunk_split(base64_encode($content));
 
    $uid = md5(uniqid(time()));
    $name = basename($file);
 
    $header = "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
    $header .= "This is a multi-part message in MIME format.\r\n";
    $header .= "--".$uid."\r\n";
 
    # These two lines to avoid SPAM:
    $header .= "Message-ID: <192.168.74.58.@ter.teradyne.com:>";
    $header .= "X-Mailer: PHP v".phpversion()."\r\n"; 
 
    $header .= "Content-type:text/html; charset=iso-8859-1\r\n\r\n";
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $header .= "".$message."\n"; 
 
    $header .= "--".$uid."\r\n";
    $header .= "Content-Type: application/octet-stream; name=\"".$name."\"\r\n";
    $header .= "Content-Transfer-Encoding: base64\r\n";
    $header .= "Content-Disposition: attachment; filename=\"".$name."\"\r\n\r\n";
    $header .= $content."\r\n\r\n";
    $header .= "--".$uid."--";
 
    
 
#   .....................................................................................
#      Subject Line of the Email Message
#   .....................................................................................
 
    $subjLine .= ' [Ticket# ';
    $subjLine .= $ticketID;
    $subjLine .= ']';
#   --------------------------------------------------------------------------------
 
 
    $status = @mail("User@Notes.SomeCompany.com", $subjLine, $message, $header);
 
 
    if($status) { 
 
        echo "<font face=verdana size=2>The file was successfully sent!</font>"; 
    } 
 
    else { 
 
        die("Sorry but the email could not be sent. Please go back and try again!"); 
    } 
 
?>
 
Post Reply