Jump to content

Sometimes emails with attached mp3's play, sometimes they don't


njdubois

Recommended Posts

Let me start out by saying I do not think that the code is the problem.

 

Here is the issue.  I have comments box much like any other page.  The comment box saves the comment to a database and sends the comment as email to the right person.  This comments box is on a page that is sort of like a report card for a phone call.  When filling out the comment box, you have the option to include the audio file for the phone call.

 

This is where the problem starts.  On both my Android Nexus 4 and my clients Iphone 5.  Both of us using Gmail and the gmail apps on our individual phones.  Sometimes we can just click the attached mp3 and it works.  And sometimes it doesn't.

 

It gets weirder.  He sent one this morning that worked for me.  When he sent the next about an hour ago neither the one he just sent me, or the new one would play?  From then on, I have not been able to send myself one that I can play.  I can long press it, or hit the more options button, save the file, browse to the file with a file explorer and open it.  It then plays no problems.  Not in the email app, but opening it like any other mp3 on my phone.

 

I have not had much experience with the iphone, but because its happening to both of us, I'm thinking its Gmail, or the GoDaddy mail system.  We have our page hosted on godaddy.

 

Here is the chunk of code that is sending emails, the top half of the if is when the user has chosen to not attach the mp3.  The bottom half is, you will see that the code stops getting indented, I wasn't sure what was what and didn't want to break something by adding a tab in there.

if($audio_filename=='') {
		
	$headers = 'From: no-reply@marcomtech.com' ."\r\n".
	'Reply-To: no-reply@marcomtech.com' ."\r\n" .
	'MIME-Version: 1.0' . "\r\n" .
	'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
	'X-Mailer: PHP/' . phpversion();

	$mail_sent = @mail($to, $email_subject, $email_message, $headers);

}
else {

	$path = '../audio_upload/' . $audio_filename;
	$path_name=$audio_filename;

	//$to = $email_to; 
	$subject = $email_subject; 



	//create 2 boundary strings. They must be unique
	$boundary1 = rand(0,9)."-".rand(10000000000,9999999999)."-".rand(10000000000,9999999999)."=:".rand(10000,99999);
	$boundary2 = rand(0,9)."-".rand(10000000000,9999999999)."-".rand(10000000000,9999999999)."=:".rand(10000,99999);

	$fileContent =  chunk_split(base64_encode(file_get_contents($path)));

	$html_message = $email_message;

$headers     =<<<AKAM
From: no-reply@marcomtech.com
MIME-Version: 1.0
Content-Type: multipart/mixed;
    boundary="$boundary1"
AKAM;

$attachment = <<<ATTA
--$boundary1
Content-Type: application/octet-stream;
    name=$path
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
    filename=$path_name

$fileContent

ATTA;

$body = <<<AKAM
This is a multi-part message in MIME format.

--$boundary1
Content-Type: multipart/alternative;
    boundary="$boundary2"


--$boundary2
Content-Type: text/html;
    charset=ISO-8859-1;
Content-Transfer-Encoding: 7bit

$html_message

--$boundary2--

$attachment
--$boundary1--
AKAM;

//send the email
$mail_sent = @mail($to, $email_subject, $body, $headers);
}
	

	if ($mail_sent) { 
		 echo $status.':'.$to.'  ';
	}
	else { 
		$EMAIL_OUTPUT_HTML.= "Message could not be sent to ".$to;
		echo $EMAIL_OUTPUT_HTML;
	} 



}

If there is anything you can tell me about the above code that may be causing my issue I would be appreciative!  If its not the code, what else could it be?  Should I be troubleshooting with godaddy?  Or Gmail?

 

Thanks!!

 

Nick

 

 

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.