gmail attachment issues

This one has me stumped.

I have to send a spreadsheet as an attachment. The code I have does it, but its failing on gmail. I don’t know if its something on their end or if its an issue with the headers, but either way, i’m tired of messing with it.

My code as it stands now
[php]$to = "[email protected]";
$subject = ‘PRIORITY: Venzo Digital Priority List/HistList - ‘.$sdate;
$random_hash = md5(date(‘r’, time()));
$headers = “From: ADAM [email protected]”."\r\n";
$headers .= “Cc: [email protected]”."\r\n";
$headers .= “MIME-Verson: 1.0”;
$headers .= “Content-Type: multipart/mixed; boundary=“PHP-mixed-”.$random_hash.”"";
$attachment = chunk_split(base64_encode(file_get_contents(’…/itunes_marketing/’.$filename)));

ob_start(); //Turn on output buffering
–PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary=“PHP-alt-<?php echo $random_hash; ?>”

–PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset=“iso-8859-1”
Content-Transfer-Encoding: 7bit

Hi iTunes,

ADAM here. I just want to inform you that the attachment provided is the Priority List/HitList provided by Venzo Music for the store date of: <?=$sdate?>

Please send this list to the appropriate Program Editor to secure possible feature placements on the iTunes Store. A Venzo Digital Representative will reach out to you within 24-72 hours with additional marketing materials to further provide the best possible review.

We thank you for reviewing our list and hope that you feature our titles. Thank you for being a Valued Partner!


Intranet Personality (Automated System)
Venzo Digital

–PHP-alt-<?php echo $random_hash; ?>–

–PHP-mixed-<?php echo $random_hash; ?>
Content-Type: application/; name="<?=$filename?>"
Content-Transfer-Encoding: base64
Content-Disposition: attachment

<?php echo $attachment; ?>

–PHP-mixed-<?php echo $random_hash; ?>–

<?php $message = ob_get_clean(); $mail_sent = @mail( $to, $subject, $message, $headers ); echo $mail_sent ? "Mail sent to $to" : "Mail failed"; ?>[/php]

I pulled the code from a websheets tutorial, it works fine with Hotmail (which is what I use), just not with gmail, unsure of other applications.

I would rewrite it using PHPMailer, the built-in mail function is crap.

Here is an phpmailer example with attachments


$mail = new PHPMailer(); // defaults to using php “mail()”

$mail->AddAddress(‘[email protected]’, “John Doe”);
$mail->SetFrom(‘[email protected]’, ‘First Last’);
$mail->AddReplyTo("[email protected]",“First Last”);

$mail->Subject = “PHPMailer Test Subject via Sendmail, basic”;

$body = file_get_contents(‘contents.html’);
$body = eregi_replace("[]",’’,$body);

$mail->AltBody = “To view the message, please use an HTML compatible email viewer!”; // optional, comment out and test

$mail->AddAttachment(“images/phpmailer.gif”); // attachment
$mail->AddAttachment(“images/phpmailer_mini.gif”); // attachment

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo “Message sent!”;

Hadn’t really wanted to rewrite the code, but switching did fix the problem once I figured out that the file path isn’t separate from the filename.

Thanks again for the help :slight_smile:

had a similar issue last night, sending a PDF as an attachment. I wrote a script that works. see this post it works on gmail also.

Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service