Solved

PHP mail and hotmail problem...

Posted on 2008-10-30
17
990 Views
Last Modified: 2012-05-05
Hi there;

I have a huge project that must mail to the users with attachment...

But an interesting thing...

in Hotmail accounts:
the mail is accepted as spam...and it's not found in inbox but in spam folder...Moreover, the attachments are going to hotmail accounts as 0 bytes...The other accounts gmail etc... works perfectly...

The server that code resides has the following information attached as jpg file...

I am sending the code snippets first part is the functions part...Second part is where i use them...
function mail_attachment($filepath, $mailto, $from_mail, $from_name, $replyto, $subject, $message, $fileAlias) {

	$file = $filepath;

	$filename = $fileAlias;

	$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 = "From: ".$from_name." <".$from_mail.">\r\n";

	$header .= "Reply-To: ".$replyto."\r\n";

	$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";

	$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";

	$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";

	$header .= $message."\r\n\r\n";

	$header .= "--".$uid."\r\n";

	if(isset($filepath)){

		$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use diff. tyoes here

		$header .= "Content-Transfer-Encoding: base64\r\n";

		$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";

	}

	$header .= $content."\r\n\r\n";

	$header .= "--".$uid."--";

	return mail($mailto, $subject, "", $header);
 

}

//////////////////////////////////////////////////////////
 

function sendMassEmail($emailYear, $extra, $subject, $body,$filepath, $fileAlias)

{

	dbConnect();

	if($emailYear!="")

	$mailQuery = "SELECT * FROM `".getConfigVal("sqlTablePrefix",2)."_users`  WHERE `alumniYear` LIKE '$emailYear'";

	else if(!empty($_POST["mail"])){

		$mails = explode(",",$_POST["mail"]);

	}

	else $mailQuery = "SELECT * FROM `".getConfigVal("sqlTablePrefix",2)."_users` where ID='".$_REQUEST["sendemail"]."'";
 

	//echo  $mailQuery;

	// else

	//{

	//	$sendemail = split(';',$_GET['extra'] );

	//	$mailQuery = "SELECT * FROM `".getConfigVal("sqlTablePrefix",2)."_users` WHERE `alumniEmail` LIKE '$sendemail'";

	//}

	$result = null;

	if(isset($mailQuery))

	$result = dbQuery($mailQuery);

	$body = stripslashes($body);

	//echo "body -> " . $body;

	$subject = stripslashes($subject);

	//echo "subject ->" . $subject;

	if($emailYear == "%") {

		$year = getConfigVal("schoolNameLong",2) . " Alumni";

	} else if($emailYear != "FRND") {

		$year = "" . $_SESSION['year'];

		//ilki

		//$year = "Class of " . $_SESSION['alumniYear'];

		

		//$year = getConfigVal("schoolNameLong",2) . " Alumni";

		

	}// else {

	//	$year = getConfigVal("schoolNameShort",2) . " Friend";

	//}
 

	if($_SESSION['userType'] == "admin")

	{

		$from = getConfigVal("alumniWebmasterEmail",2);

		$name = getConfigVal("schoolNameShort",2) . " Alumni";

		$signature = "\n\n".getConfigVal("schoolNameLong",2)."\n".getConfigVal("alumniWebmasterName",2)."\n".getConfigVal("schoolWebsite",2)."\n". getConfigVal("alumniWebmasterEmail",2);

	}

	else{

		$from = $_SESSION['email'];

		$name = $_SESSION['firstName'] . " " . $_SESSION['lastName'];

		$signature =$_SESSION['firstName'] . " " . $_SESSION['lastName'] . "\n$year";

		//echo $year."hi";

		$webTeamSignature = "\n\n**********DISCLAIMER**********\n".getConfigVal("schoolNameLong",2)." has taken no part in creating this email.  Although we have provided a means for " . $_SESSION['alumniFirstName'] . " to send you the email, we do not endorse or assume any responsibility for it's contents.  If you wish to be removed from the $year mailing list let us know.  If you believe that this message is in any way inappropriate, forward us the email so that we can evaluate it and take any action that may be necessary.\n\nThank you,\n".getConfigVal("schoolNameLong",2)."\n".getConfigVal("schoolWebsite",2)."\n".getConfigVal("alumniWebmasterEmail",2);

	}
 

	echo "Please wait... This will take a few minutes, depending on the number of members you are emailing...<hr />Now Sending Email To:<br />";

	//echo "mehmet";

	global $cc;

	$counter = 0;

	if(count($mails)>0){
 

		for($i=0;$i<count($mails);$i++){

			$email = $mails[$i];

			if(!empty($email)){

//blabla...secil hemen alttaki satiri kaldirdi...

				//echo $email."<br>";

				//print_r($row);

				//	echo $counter . ". email -> " . $email . "<br />";

				if($email != getConfigVal("alumniWebmasterEmail",2)){

					//Send mail to user with $body (above) text

					mail_attachment($filepath, $email,$from, $name, $from, $subject, $body."\n\n".$signature."\n\n".$webTeamSignature, $fileAlias);

					//mail_attachment($filepath, $email,$subject,$body,"From: $name<$from>");

					if(!$cc) {

						$cc = $email;

					} else {

						$cc = $cc . "\n" . $email;

					}

					$counter += 1;

					$str = $_REQUEST["sendemail"];

						

						 $arr= explode(';', $str);

					echo "<strong>" . $row[3] . " " . $row[5];

					if($_SESSION['userType'] == "admin") 

					{ 

					

						//echo "bye deary";

						for($i=0;$i<sizeof($arr)-1;$i++){

						$mailQuery = "SELECT * FROM alumni_users where ID = ". ($arr[$i]);

						$result = dbQuery($mailQuery);

						if ($row = mysql_fetch_array($result)) {

							$year = $row['alumniYear'];							

							$name = $row['alumniFirstName'] ;

							$surname = $row['alumniLastName'];

							echo "<strong> ".$name." ".$surname."</strong>"; 			

							 echo "<strong> [".$year."]</strong>"; 			

							 echo "</strong> (<em>" . $mails[$i] . "</em>)<br />";

							 

						}

						}						

					

					}

					

					else

					

					{

						for($i=0;$i<sizeof($arr)-1;$i++){

						$mailQuery = "SELECT * FROM alumni_users where ID = ". ($arr[$i]);

						$result = dbQuery($mailQuery);

						if ($row = mysql_fetch_array($result)) {

							$year = $row['alumniYear'];							

							$name = $row['alumniFirstName'] ;

							$surname = $row['alumniLastName'];

							echo "<strong> ".$name." ".$surname."</strong>"; 			

							echo "<strong> [".$year."]</strong>"; 			

							 echo "</strong> (<em>" . $mails[$i] . "</em>)<br />";

							 

						}

						}						

					}

					

					//echo "</strong> (<em>" . $email . "</em>)<br />";

				}

			}

		}

	}

	else {

		while ($row = mysql_fetch_row($result)) {

			$email = $row[9];

			//blabla...secil hemen alttaki satiri kaldirdi...

			//echo $email."<br>";

			//print_r($row);

			//	echo $counter . ". email -> " . $email . "<br />";

			if($email != getConfigVal("alumniWebmasterEmail",2)){

				//Send mail to user with $body (above) text

				mail_attachment($filepath, $email,$from, $name, $from, $subject, $body."\n\n".$signature."\n\n".$webTeamSignature, $fileAlias);

				//mail_attachment($filepath, $email,$subject,$body,"From: $name<$from>");

				if(!$cc) {

					$cc = $row[9];

				} else {

					$cc = $cc . "\n" . $row[9];

				}

				$counter += 1;

				echo "<strong>" . $row[3] . " " . $row[5];

				if($_SESSION['userType'] == "admin") { echo " [".$row[33]."]"; }

				echo "</strong> (<em>" . $email . "</em>)<br />";

			}

		}

	}
 

	if($extra!="")

	//bak alttakini sildim aman diim!!!

	//mail_attachment($filepath, $extra,$from, $name, $from, $subject, $body."\n\n".$signature."\n\n".$webTeamSignature, $fileAlias);
 

	//Carbon Copy information for email to be sent to the web team

	$email = getConfigVal("alumniWebmasterEmail",2);

	$ccHead = "An email has been sent from the alumni mass email page for the $year list.  A total of $counter emails were sent to the following email addresses: \n--------------------------------------------------------------------------\n$cc\n--------------------------------------------------------------------------\n\nCARBON COPY OF EMAIL:\n--------------------------------------------------------------------------\nFrom: $name<$from>\nSubject: $subject\n\n$body" . "\n\n" . "$signature" . "$webTeamSignature\n--------------------------------------------------------------------------";

	if(isset($year))

	$subject = "An Email is Sent to $year";

	else

	$subject = "An Email is Sent to $extra";
 

	//Send a description of the email to the web team for evaluation

	//
 

	//mail($email,$subject,$ccHead,"From: $name<$from>");

	

	mail_attachment($filepath, $email, $from, $name, $from, $subject, $body, $fileAlias );

	//mail($extra,$subject,$ccHead,"From: $name<$from>");

	//else 		mail_attachment($filepath,"",$email,$from,$name,$from,$subject,$ccHead);
 

	echo "<hr /><strong>Success!</strong>  Your email has been sent.<div>&nbsp;</div>";

}
 

2.nd part////////////////////////////////////////////

<?php 

				if(!isset($_SESSION['userType'])) { echo "<br /><br />"; displaySiteError("Fatal","<strong>ACCESS DENIED!</strong><br />This section is restricted to administrators only!","die"); } 

			?>

			

			<h1><?php echo getConfigVal("schoolNameShort",2); ?> Alumni </h1>

			<? if(!$_POST['sendMail'])

			{ ?>

			<h2>Email Alumni Members</h2>

			<p><span class="bold"></span>HTML, JavaScript, PHP, and other languages are <strong>NOT</strong> allowed in emails.</p>

			<? } 

			

				$sendemail = split(';',$_GET['sendemail'] );

				//echo "damn";

				if($_POST['sendMail'])

				{

					?>

					<h2>Email Alumni Members</h2>

					<?

					$sendMailYear = $_POST['sendMailYear'];

					$subject = $_POST['subject'];

					$body = $_POST['body'];

					$mail= $_POST['mail'];

					//$mailstring = $_POST['mailstr'];

					$file = $_FILES['attachment']['tmp_name'];  

					$fileAlias = $_FILES['attachment']['name'];

					//comment out for try.project-alumni.org

					sendMassEmail($sendMailYear,$mail,$subject, $body,$file, $fileAlias);
 

				}

				else{

			?>

			<form action="" enctype="multipart/form-data" name="massEmailForm" method="post" >

				<fieldset>

						<? if(!isset($_GET['sendemail']))

						{						

						?>		

						<p><label for="to">Choose a Year:</label>

							<br />

							<?php echo displayYearList("sendMailYear",false,"","",TRUE) ?></p>

						<?}?>

						<? if(isset($_GET['sendemail']))

						{						

						?>

						<p>

						<label for="to">To: </label>

						<br />

						<input class='fieldsetFix' type='text' id='mail'  

						<?php 	

						

						$str="SELECT alumniEmail FROM alumni_users WHERE ID="; 

						$str .= $sendemail[0] ;

						

						 if(count($sendemail)>1){

							

						for ( $i=1; $i< count($sendemail)-1; $i++ ) 

						

							$str .= " OR ID=$sendemail[$i]";

							

							}

						

						 $result=dbQuery($str);

						 $mailstr="";

						 while($row=mysql_fetch_row($result))

						  $mailstr.=$row[0].",";

						 

						

						echo "value='$mailstr'" ?>  name='mail' size='57'/>

						</p>

					<?}?>

					<p><label for="subject">Subject:</label>

					<br />

					<input class="fieldsetFix" type="text" name="subject" size="57"/></p>

		

					<p><label for="body">Email Body:</label>

					<br />

					<textarea class="fieldsetFix" name="body" cols="57" rows="10" ></textarea>

					</p>

					<p><label for="body">Email Attachment:</label>

					<br />

					<input class="fieldsetFix" type="file" name="attachment">

					</p>

					

					<p><input class="fieldsetFix" type="submit" name="sendMail" value="Send Email" /></p>

				</fieldset>

			</form>

			<?php }

			

			

			

			?>

Open in new window

0
Comment
Question by:jazzIIIlove
  • 11
  • 4
17 Comments
 
LVL 4

Expert Comment

by:MattKenefick
ID: 22846081
Hotmail marking your email as spam doesn't have anything to do with PHP really, as far as I know.

It has to do with content (image vs text ratio, keywords that set off the spam filter), proper headers and sender of course (which could involve PHP), and reliable source.

As I recall, they use a points system to determine if something is spam.

Example:
  Too many images = +2
  Word "Viagra"   = +10
  No Headers = +5
  etc

If it goes over 11 points (or whatever the magic number is) then you're marked as spam.

It's not necessarily PHP, but Hotmail itself.
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 22846600
so what about my headers...Any problem?
0
 
LVL 82

Expert Comment

by:hielo
ID: 22847017
Two different issues going on. The fact that it ends in the spam is related to your content.  "Spam keywords" tend to drive it to the spam folder.

As for the size of the file, I got zero 0bytes when I was typing the path of the file incorrectly ( I suggest you add logic to verify the existence of the file before you attempt to attach it). You need to provide the absolute path to the attachment. So instead of  providing the path as:
"announcement_1.pdf"

you need something like:
$_SERVER['DOCUMENT_ROOT'] . "/announcements/announcement_1.pdf"
(assuming the path to your file is: http://www.company.com/announcements/announcement_1.pdf")

After I adjusted the file path, I managed to receive the attachment that said zero Kb, BUT did have content. The original file I was using was a text file and simply had "Some Testing Content" in it. Clearly this is LESS than 1000 bytes, so it was reported as 0Kb.

The only other suggestion would be to add a Content-Length header, and use the size of the file content as the value.

On my last test, I do see the correct file size in my hotmail account when I used a pdf file.
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 22850149
hielo...thanks for your great effort...this is real pain in the ass...I will be probing your solution 24 hours later because i am sleepless and will definitely inform you related with my problem...Because this is the most important question i have ever been asking since i enrolled this site...
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 22857334
Hi hielo;

>>Two different issues going on. The fact that it ends in the spam is related to your content.  "Spam >>keywords" tend to drive it to the spam folder.
We have no Spam keyword in the content or do you mean in my code? (I have no spam keyword in the project:)

>>I suggest you add logic to verify the existence of the file before you attempt to attach it). You need to >>provide the absolute path to the attachment. So instead of  providing the path as:
>>"announcement_1.pdf"
>>you need something like:
>>$_SERVER['DOCUMENT_ROOT'] . "/announcements/announcement_1.pdf"
>>(assuming the path to your file is: http://www.company.com/announcements/announcement_1.pdf")
Sorry if I miss stg but the thing i don't understand above is that the pdf you attached is static...But my attachments are specified dynamically by the admin by a browse button...So, is it still logical to add a line like that and upload the pdf to my server? Is your intention have a temp file and you can replace?

>>The only other suggestion would be to add a Content-Length header, and use the size of the file >>content as the value.
That i add but i don't know if i did wrong...

I attach the code snippet and having some trivial debugging and i see that there is a temp file created and i see the name of the file as in the hielo2.jpg file...

I attach the code, a little modified for debugging and you can check the results in hielo2.jpg...
You are my last hope...and you are the best...

Best regards...
$sendemail = split(';',$_GET['sendemail'] );

				//echo "damn";

				if($_POST['sendMail'])

				{

					?>

					<h2>Email Alumni Members</h2>

					<?

					$sendMailYear = $_POST['sendMailYear'];

					$subject = $_POST['subject'];

					$body = $_POST['body'];

					$mail= $_POST['mail'];

					//$mailstring = $_POST['mailstr'];

					//$file = $_FILES['attachment']['tmp_name'];  

					//$fileAlias = $_FILES['attachment']['name'];

					//below is wrong?

					$f1 = $_SERVER['DOCUMENT_ROOT'] .$file;

					$f2 = $_SERVER['DOCUMENT_ROOT'] .$fileAlias;

					echo "+++"."$file"."+++";

					echo "---".$fileAlias."---";

					echo "123".$filename."321";

					echo "abc".$f1."cba";

					echo "xyz".$f2."zyx";

					

					echo "damn";

					$file = $_FILES['attachment']['tmp_name'];  

					$fileAlias = $_FILES['attachment']['name'];

					

				

					sendMassEmail($sendMailYear,$mail,$subject, $body,$file, $fileAlias);
 

				}
 

////////////////////////////////////////////////////////////
 

function mail_attachment($filepath, $mailto, $from_mail, $from_name, $replyto, $subject, $message, $fileAlias) {

	$file = $filepath;

	//$file = $fileAlias;

	//$filepath = $fileAlias;

	echo "111".$file."111";

	echo "222".$filepath."222";

	echo "333".$mailto."333";

	echo "444".$from_mail."444";

	echo "555".$from_name."555";

	echo "666".$replyto."666";

	echo "777".$subject."777";

	echo "888".$message."888";

	echo "999".$fileAlias."999";

	$filename = $fileAlias;

	$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 = "From: ".$from_name." <".$from_mail.">\r\n";

	$header .= "Reply-To: ".$replyto."\r\n";

	$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";

	$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";

	$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";

	$header .= $message."\r\n\r\n";

	$header .= "--".$uid."\r\n";

	if(isset($filepath)){

		$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use diff. tyoes here

		$header .= "Content-Transfer-Encoding: base64\r\n";

		//very fresh

		//ob_start();

		//$_SERVER['DOCUMENT_ROOT'] . "/announcements/announcement_1.pdf";

		//$header.='Content-Length: ' . ob_get_length();
 

		//ob_end_flush();

	

		

		$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";

	}

	$header .= $content."\r\n\r\n";

	$header .= "--".$uid."--";

	return mail($mailto, $subject, "", $header);
 

}

////////////////////////////////////////////////////////

Open in new window

0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 22869266
hielooooo...:)
0
 
LVL 82

Expert Comment

by:hielo
ID: 22872505
jazzIIIlove,
you need to learn to be patient. Harassing community support folks is unacceptable. I do NOT work for EE. I volunteer my time. If I am not able to attend to your question(s) you are always welcomed to delete them so others can help you. I was away most of the day today, so there are quite a few questions that need to be looked at. You are NOT the ONLY one that has problems. I try to HELP people the best I can. If it is urgent (to you), then perhaps you should hire a consultant.
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 22872983
no...not that urgent but i was curious about the solution...I am really sorry about this...I appreciate your effort very much indeed...

Best regards...
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 82

Expert Comment

by:hielo
ID: 22876746
As of now, I believe the solution is not yet known. What I tried/tested, worked fine for me, but it seems that there is something else happening. So, let me summarize what I did, and you repeat my steps to see if you get the same results I got OR if you get the (undesired) results you have been seeing. The objective is to investigate what we have done differently.

My php test file has just ONE function =>function mail_attachment()
So, I am calling it directly. You are calling it via function sendMassEmail(). Also, I have a test attachement file already saved in my folder. You are attempting to attach an uploaded file.

So, for testing purposes, copy function mail_attachment() to file named test.asp can call it directly. Also, save some test.pdf file to your server BEFORE you run the test script and try sending that as the attachment. In other words, forget about sending an uploaded file for now to see what's the outcome.
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 22906221
I am applying your suggestion...
well i have got a major problem...that is:
Forget about attachment, the body part of the mail cannot be retrieved by hotmail...gmail and other can get it...but not hotmail...i comment sendMassEmail function and directly copy the content to the function call...No use yet...the body is not going...interesting...I am on it...If you have any other suggestions, please let me now...

Best regards...
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 22907071
Hi hielo;

I think i couldn't figure out setting the file path...Could you assist on this please? (Apparently below is not correct...)

$file = $_FILES['attachment']['tmp_name'];
echo $file."asdf";
//$fileAlias = $_FILES['attachment']['name'];

Best regards...
$fileAlias = "/var/www/html/abc/zxy/somefile.txt";

0
 
LVL 82

Assisted Solution

by:hielo
hielo earned 500 total points
ID: 22909182
>>I think i couldn't figure out setting the file path...
earlier you said "Forget about attachment, the body part of the mail cannot be retrieved by hotmail"
have you resolved that part? Are you now getting the body?

As for "I think i couldn't figure out setting the file path...", did you try a static file? Meaing, a file that is already saved in your server. Currently I see you are trying to attach a file that you are uploading. Try a file that is already saved in your server. So, start by saving some test.pdf file to:
http://www.yoursite.com/testing/test.pdf

then call your function as follows:

$filepath = $_SERVER['DOCUMENT_ROOT'] . "/testing/test.pdf";
 mail_attachment($filepath,...)

As for:
$file = $_FILES['attachment']['tmp_name']; ( Apparently below is not correct...)
I prefer you try sending a file that is already in your server first. You are currently trying to attach a file hat is NOT yet saved within your web space, so you may have to use move_uploaded_file() first:
http://us.php.net/manual/en/function.move-uploaded-file.php

so that you move the file to your webspace and then attach from within your webspace. But try my previous suggestion first so that once you get that working you will know for a fact that your script is emailing attachements. The next step would be to figure out why it is not attaching uploaded files. One step at a time.
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 22912903
Hi hielo;

I tried this and echoed the filepath, I can see the filepath but still hotmail resists to get the file...

$filepath = $_SERVER['DOCUMENT_ROOT'] . "/testing/test.pdf";
 mail_attachment($filepath,...)

For the message body: Again, Hotmail resists to see the body, only subject...What is your strategy if you were me?

Best regards...
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 22913518
well...we have got a progress here:

The funny thing is still i couldn't have seen the body if there was an attachment...

So:

I isolate the mail sending code and check for the accounts for hotmail and rewrite the code...lol

well the logic if there is attachment blabala
else only send the mail...So only send the mail is working...subject, body etc...all ok in Hotmail...

But when there is attachment, again i can send the mail but the attachment must be txt extension, otherwise no use...AND THERE IS NO BODY...I EVEN CHECK THE BODY BEFORE SENDING, IT'S OK BUT HOTMAIL DOESN'T GETS...IN FACT HE GETS THE BODY AND HE SIMPLY OVERRIDES THE CONTENT OF DOC ATTACHMENT:

Content-Type: multipart/mixed; boundary="Ï à¡± á

niçin

'niçin' should be the body but it's in the attachment...

Below, the attachment must start with Thank you...instead below...In the very end of attachment, the body is appended (Scooby do where are you)...

TXT file result in hotmail:
Content-Type: multipart/mixed; boundary="Thank you for contacting Acronis! The chat operator will be with you approximately in 0 minute(s) and 20 seconds. Thank you for waiting.

....
scooby do where are you

I say fclose to the file but he is appended...He has opened in read mode...I cannot understand how a file which is closed can be appended like that?

I am attaching the code snippet and in the end of snippet...Please check and help me...

Best regards...
	$arrExploded = explode("@",$mail);

					//echo $arrExploded[0]."qwer";

					//echo $arrExploded[1]."rtu";

					$hotmailCheck = substr($arrExploded[1],0,strlen($arrExploded)-1);

					//echo $hotmailCheck."qwer";

					if($hotmailCheck == "hotm")

					{

				$file = $_FILES['attachment']['tmp_name'];  

		$fileAlias = $_FILES['attachment']['name'];

		$filepath = $file;

	$filename = $fileAlias;

	

		if(isset($filepath)){

			$handle = fopen($file, "r");

			$file_size = filesize($file);

	$content = fread($handle, $file_size);

	fclose($handle);

	//$content = chunk_split(base64_encode($content));		

						$from = getConfigVal("alumniWebmasterEmail",2);

		$name = getConfigVal("schoolNameShort",2) . " Alumni";

		$signature = "\n\n".getConfigVal("schoolNameLong",2)."\n".getConfigVal("alumniWebmasterName",2)."\n".getConfigVal("schoolWebsite",2)."\n". getConfigVal("alumniWebmasterEmail",2);

						

						$header = "From: ".$name." <".$from.">\r\n";

	$header .= "Reply-To: ".$from."\r\n";

	$header .= "MIME-Version: 1.0\r\n";	

		$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use diff. tyoes here

		//$header .= "Content-Transfer-Encoding: base64\r\n";

		$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";

	$header .= "Content-Type: multipart/mixed; boundary=\"";

	//$header .= "This is a multi-part message in MIME format.\r\n";

	//$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";

	//$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";

	//$header .= $body."\r\n\r\n";

	//$header .= "--".$uid."\r\n";

		

			$header .= $content."\r\n\r\n";

			$header .= $uid."\"\r\n\r\n";

							mail($mail,$subject,$body,$header);

	}

	else{

		$header .= $uid."\"\r\n\r\n";
 

						mail($mail,$subject,$body,$header);

	}

Open in new window

0
 
LVL 12

Accepted Solution

by:
jazzIIIlove earned 0 total points
ID: 23031960
At last:

I solved it...

I rewrite the code...But this time, it works only for hotmail...so an if check...Code is as snippet...

Best regards...
function mail_attachment($filepath, $mailto, $from_mail, $from_name, $replyto, $subject, $message, $fileAlias) {

	//echo $message;

			$arrExploded = explode("@",$mailto);

					//echo $arrExploded[0]."qwer";

					//echo $arrExploded[1]."rtu";

				$hotmailCheck = substr($arrExploded[1],0,strlen($arrExploded)-1);

					//echo $hotmailCheck."qwer";

					if($hotmailCheck == "hotm")

					{

					//echo $mailto."To?";

				$file = $_FILES['attachment']['tmp_name'];  

	$fileAlias = $_FILES['attachment']['name'];

		$filepath = $file;

	$filename = $fileAlias;

	//echo $filename."sdf";

	//echo $mesaj."1234";

		if(isset($filepath)){

	$from = getConfigVal("alumniWebmasterEmail",2);	

	$alici = $mailto;

    //$mesaj = "Merhabalar nasilsin deneme mesaji"; 

    //$konu = "Testing file"; 

    # Upload edilen dosyayi ac 

    $data = fread(fopen($file, "rb"), filesize($file)); 

    # Dosyanin asil adi 

    

    

    # Dosyanin tipi, mesale jpeg/msword/pdf 

    $type = $_FILES['file']['type']; 

    

    # Attachmen base64 ile kodlanmali ve chunk ile dogruyoruz 

    $attachment = chunk_split(base64_encode($data));          

    # Boundry multipart bolumlerinin ayrimi, random uretilir 

    $boundry = "-----=".md5(uniqid(rand())); 

     

    $header  = "From:".$from_mail."\r\n";     

    $header .= "To: $mailto\r\n";     

    //$header .= "Subject: $subject\r\n"; 

    # Eger priorty ve extra header gondermek isterseniz buradan kullanabilirsiniz 

    /* 

    $header .= "Date: Wed, 23 Jul 2003 19:52:35 +0200\r\n"; 

    $header .= "Message-ID: <000001c35143$36542a10$0c2dfea9@oguzpc>\r\n"; 

    $header .= "X-Priority: 3\r\n"; 

    $header .= "X-Envelope-To: <$alici>\r\n"; 

    $header .= "X-Envelope-From: <test@netfront.nl>\r\n"; 

    $header .= "X-Mailer: Netfront mailserver\r\n";  

    */ 

    $header .= "MIME-Version: 1.0\r\n";     

    $header .= "Content-Type: multipart/mixed;"; 

    $header .= "\tboundary=\"$boundry\"\n\n"; 

    # RFC  standardina gore multipart MIME body tanimlama 

    $body  = "This is a multi-part mesaj in MIME format.\n"; 

    $body .= "--$boundry\n\n";     

    //$body .= "Content-Type: text/plain;\n"; 

    //$body .= "\tcharset=\"us-ascii\"\n";     

    //$body .= "Content-Transfer-Encoding: 7bit\n\n";      

    $body .= "$message\n\n";     

    $body .= "--$boundry\n"; 

    $body .= "Content-Type: $type;\n"; 

    $body .= "\tname=\"$filename\"\n"; 

    $body .= "Content-Transfer-Encoding: base64\n";      

    $body .= "Content-Disposition: attachment\n"; 

    $body .= "\tfilename=\"$filename\"\n\n"; 

    $body .= $attachment."\n\n"; 

    $body .= "--$boundry--\n";        

    # Maili gonder 

    mail($mailto, $subject, $body, $header); 
 

	}

	else{

		$body = "$message\n";  

		$header  = "From:".$from_mail."\r\n"; 

		//echo $from_mail."aa";

		//echo $from_name."bb";

		$header .= $uid."\"\r\n\r\n";
 

						mail($mailto,$subject,$body,$header);

	}

					}

					

					else 

					{

	$file = $filepath;

	$filename = $fileAlias;

	$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 = "From: ".$from_name." <".$from_mail.">\r\n";

	$header .= "Reply-To: ".$replyto."\r\n";

	$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";

	$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";

	$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";

	$header .= $message."\r\n\r\n";

	$header .= "--".$uid."\r\n";

	if(isset($filepath)){

		$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use diff. tyoes here

		$header .= "Content-Transfer-Encoding: base64\r\n";

		$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";

	}

	$header .= $content."\r\n\r\n";

	$header .= "--".$uid."--";

	return mail($mailto, $subject, "", $header);

	}		

}

Open in new window

0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 23044813
thank you Lunchy...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
php mail headers 2 13
WooCommerce Sort by Date 4 10
get radio button vale in array 7 37
PHP string issue 5 18
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now