Jump to content

MIME php script stops working - no change to code


ragsr@ix.netcom.com

Recommended Posts

Thanks in advance for any help you can provide on this.  Bob G.

 

BACKGROUND:  I have an app that is hosted on Host Monster and its script includes a Class that is supposed to send MIME emails with or without attachments using only MIME types text, html, and image.  It was working fine.  I hadn't worked with or on it for about two months then found, last week, that it would no longer send emails even though the script runs without any Warnings.  I've worked on this for several days now and I'm stuck.

EXPECTED BEHAVIOR: When the script runs, it should send a simple text only email to a given email address and an more complex email that requires html and an in-line image in the body and an attachment with the same image.  The image type is jpeg.

ACTUAL BEHAVIOR: The script runs to completion with no Warning but sends neither of the two emails.

CODE:

Attached and cc'd below is a script which mimics the code in my app and the actual behavior described above but only for the simple email mentioned above.  To simplify debug I've commented out that part of the script that should send out the more complex email mentioned above.

    Note: You can run the script by going to http://www.unitresearch03.com/Admin/SendUserEmailHM01.php

    Note: Line 6 can be changed to your own email address for testing

 

BEGIN CODE:

<?php
//TOP LINE CODE 
////SIMPLE MIME EMAIL CODE - NO ATTACHMENTS //////////////////////////////////////////////
$mail = new mime_mail ;

$mail->from = "ragsr@ix.netcom.com" ;
$mail->to = "ragsr@ix.netcom.com" ;
$mail->subject = "SIMPLE MIME EMAIL - NO ATTACHMENTS"  ;
$mail->body = "SIMPLE MIME EMAIL BODY" ;

$mail->send() ;

////END OF SIMPLE MIME EMAIL CODE  ////////////////////////////////////////////////////////


////START MIME EMAIL CODE - ALLOWS ATTACHEMENTS  /////////////////////////////////////////////////
//SIMPLE SEND EMAIL PG.448 PHP REFERENCE PLUS ATTACHMENT EXAMPLE FROM SAME PAGE
//include  "mime_mail.inc";  //THIS CAUSED A WARNING AND, APPARENTLY, IS NOT REQUIRED.  CODE OK W/O IT

//READ FILE
$filename="/home1/unitcons/public_html/unitresearch03/TCStripComposition-27Cb.jpg" ;
$content_type="image/jpeg" ;

//OPEN, EXTRACT DATA, THEN CLOSE FILE
$fd=fopen($filename, "r") ;
$data=fread($fd, filesize($filename)) ;
fclose($fd) ;
$fileX="/home1/unitcons/public_html/unitresearch03TCStripComposition-27Cb.jpg" ;
$ftype=filetype ($filename) ;
$fsize=filesize($filename) ;
//echo "FILE TYPE :"."$ftype"."<br>" ;
//echo "FD FILE TYPE :"."$fdltype"."<br>" ;
//echo "DATA :"."$data"."  END DATA"."<br>" ;
//echo "FSIZE :"."$fsize"."<br>" ;
//echo "FDSIZE :"."$fsize"."<br>" ;
//echo "FD :"."$fd"."<br>" ;


//CREATE OBJECT INSTANCE
$mail = new mime_mail ;


//SET ALL DATA SLOTS
$mail->from 	= "thromptmweeklycs@unitresearch03.com" ;
$mail->to	= "ragsr@ix.netcom.com" ;
$mail->subject  = "XXXThrompTM Weekly Comic Strip - Week of 6/20/201" ;
$mail->body	= "<html>Hope you enjoy your ThrompTM today!
<br>
<br>
<br>
<img src=http://www.unitresearch03.com/TCStripComposition-27Cb.jpg height='197'  width='500' >
</html>";

//DEFINE ATTACHMENT
$name = $fileX ;
$message = $data ;
//ADD ATTACHEMENT
//$mail->add_attachment ($data, $filename, $content_type) ;

//SEND EMAIL
//$mail->send() ;
////EBD SEND EMAIL WITH ATTACHMENT



////MIME CLASS

class mime_mail
{
var $parts;
var $to;
var $from;
var $headers;
var $subject;
var $body ;
/*
*	void mime_mail()
*	class constructor
*/

function mime_mail ()
{
$this->parts = array() ;
$this->to = "" ;
$this->from = "" ;
$this->subject = "" ;
$this->body = "" ;
$this->headers = "" ;
}


/*
*	void add_attachement (string message, [string name], [string ctype])
*	Add an attachment to the mail object
*/

function add_attachment ($message, $name = "", $ctype = "text/html jpeg" )
//function add_attachment ($data, $fileX, $content_type )
{

echo "CTYPE IN AA :"."$ctype"."<br>" ;
//echo "MESSAGE IN AA :"."$message"."<br>" ;
echo "ENCODE IN AA: "."$encode"."<br>" ;
echo "NAME IN AA :"."$name"."<br>" ;
//echo "DATA IN AA :"."$data"."<br>" ;

$partsd =	$this->parts[] = array (
	"ctype" => $ctype,
	"message" => $message,
	"encode" => $encode,
	"name" => $name,
               				);
echo ("ARRAY#1 CTYPE :"."$partsd[ctype]"."<br>") ;
//echo ("ARRAY#2 MESSAGE :"."$partsd[message]"."<br>") ;
echo ("ARRAY#3 ENCODE :"."$partsd[encode]"."<br>") ;
echo ("ARRAY#4 NAME :"."$partsd[name]"."<br>") ;
//echo ("ARRAY#5 DATA :"."$partsd[data]"."<br>") ;
$sizeX=sizeof($this->parts) ;
echo "SIZE OF ARRAY IN ADD ATTACHMENT:"."$sizeX"."<br>" ;

}

/*
*	void build_message (array part=
*	Build message parts of an multipart mail
*/

function build_message ($part )
{
$message = $part[ "message"];
//echo "MESSAGE IN BUILD:"."$message"."<br>" ;
$message = chunk_split(base64_encode($message)) ;
//echo "MESSAGE :"."$message"."<br>" ;
$encoding = "base64" ;
$partctype = $part["ctype"] ;
$partname = $part["name"] ;
echo "PART CTYPE :"."$partctype"."<br>" ;
echo "PART NAME :"."$partname"."<br>" ;

	return "Content-Type: ".$part["ctype"].
	($part["name"]?" ; name =\"". $part["name"].
	"\"":"").

	"\nContent-Transfer-Encoding: $encoding\n\n$message\n" ;
}

/*
*	void build_multipart()
*	Build a multipart mail
*/

function build_multipart()
{

$boundary = "b".md5(uniqid(time())) ;
$multipart = 
	"Content-Type: multipart/mixed; boundary = $boundary\n\nThis is a MIME 
	encoded message.\n\n--$boundary" ;
//$sizeX=sizeof($this->parts) ;
//echo "SIZE OF ARRAY :"."$sizeX"."<br>" ;
	for ($i = sizeof($this->parts)-1; $i >= 0; $i--)
{
	$multipart .= "\n".$this->build_message($this->parts[$i])."--$boundary" ;
	//echo "MULTIPART :"."$multipart"."<br>" ;
}
       return $multipart.= "--\n" ;
}
/*
*	string get_mail()
*	returns the constructed mail
*/

function get_mail($complete = true)
{ $complete = true ; echo "COMPLETE :"."$complete"."<br>" ;  ////STAEMENT ADDED TO FORCE IF ($COMPLETE) {} BELOW TO RUN
//echo "MESSAGE IN GET MAIL:"."$message"."<br>" ;
$mime = "" ; 
if (!empty($this->from))
	$mime .= "From: ".$this->from. "\n" ;
echo "MIME 1:"."$mime"."<br>";
if (!empty($this->headers))
$mime .= $this->headers. "\n" ;
echo "MIME 2:"."$mime"."<br>";
if ($complete) 
{
echo "MIME 3:"."$mime"."<br>";
	if (!empty($this->to)) 
{
		$mime .= "To: $this->to\n" ;
echo "MIME 4:"."$mime"."<br>";

}
	if (!empty($this->subject))
{
		$mime .= "Subject: $this->subject\n" ;
echo "MIME 5:"."$mime"."<br>";

}
}

if (!empty($this->body)) 
               $this->add_attachment($this->body, "", "text/html");

echo "MIME 55:"."$mime"."<br>";


	$mime .= "MIME-Version: 1.0\n".$this->build_multipart() ;
echo "MIME 6:"."$mime"."<br>";

	return $mime;
}

/*
*	void send()
*	Send the mail (last class-function to be called)
*/

//function send ($message, $data, $fileX, $content_type)
function send ()
{
//$bodyY=$this->body ;
//echo "BODYY :"."$bodyY"."<br>" ;

$mime=$this->get_mail () ;
echo "MIME 7:"."$mime"."<br>" ;
mail($this->to, $this->subject, "" , $mime) ;
//mail($this->to, $this->subject, $this->body, $mime) ;

}
}
; 

////END OF MIME CLASS CODE /////////////////////////////////////////////////////////////////

?>

END CODE:

 

17525_.txt

Link to comment
Share on other sites

  • 2 weeks later...

This problem has been solved.  The php script was find.  The inabilty to receive emails sent by the script was isolated to my EarthLink email server.  Earthlink's SpamBlocker SW stopped working correctly and would not allow email sent from my "From" email address in my MIME email script to get through to my desktop.  This was the case despite the fact that I had tagged that address as non-Spam in Earthlink's SpamBlocker.  Earthlink escalated the problem.  My work around, until this is permantely fixed, is to turn Earthlinks SpamBlocker.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.