/    Sign up×
Community /Pin to ProfileBookmark

faulty e-mails

I’m struggling with an e-mail problem. Here goes:

I’ve created an e-mail program that sends a pdf file to stated e-mail address. It took me a while until I got everything working perfectly. All my tests to Hotmail, Yahoo, and Outlook worked fine. In celebration I e-mail a few other people to test and they found a few problems. Some e-mail programs “explode” the pdf file and the message body displays code-like characters. Hotmail is continuing to be troublesome and works one day and not the other.

I so badly want to finish this function and desperately need some help. I’ll be happy to show code or answer any other questions concerning my code. If someone can shed light on my mishap I’d be grateful. Thanx.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@PittimannJan 17.2004 — Hi!

Could you please post your code for a check??

It seems, you're not attaching the file properly. Another question: is the .pdf on your local hdd or on a server?

Cheers - Pit
Copy linkTweet thisAlerts:
@neumyauthorJan 19.2004 — Here's just my main mailing code:

if ($REQUEST_METHOD=="POST")

{

$id = $_POST['testid'];

$product = $_
POST['product'];

if (assessment_auth($id,$product))

{

$result = func_query_first("SELECT score, productid, DATE_FORMAT(FROM_UNIXTIME(last_updated),'%M %e, %Y') AS completed, comments FROM $sql_tbl[scores] WHERE testid = '$id'");

$score= Unserialize($result['score']);

$showdate = $result['completed'];

$notes = $result['comments'];

$report = "This is a test!nI don't know if this will work, but here is the results:nSelf = ".$score['part1'][S]."nFamily = ".$score['part1'][F]."nPeers = ".$score['part1'][P]."nWork = ".$score['part1'][W]."nProjected Self = ".$score['part1'][J];



$email = $_POST['mail_to'];
$message = send_mail($email);
// need to check e-mail address
}
else {
header("Location: error_message.php?permission_denied");
}

}

function send_mail($mail_to)

{

if(empty($mail_to)) return "Please input who you'd like to e-mail this to";

$mail_to = str_replace(";",",",$mail_to);

$mail_parts["mail_to"] = $mail_to;
$mail_parts["mail_from"] = ""The Report" <[email protected]>";
$mail_parts["mail_reply_to"] = ""Report" <[email protected]>";
$mail_parts["mail_subject"] = "Here is the report you requested";
$mail_parts["mail_body"] = "Thank you for taking the assessment.";

if(my_mail($mail_parts)) return "Successfully sent report";
else return "An unknown error occurred while attempting to send report";

} // function send_mail()

function my_mail($mail_parts)

{

$mail_to = $mail_parts["mail_to"];

$mail_from = $mail_parts["mail_from"];

$mail_reply_to = $mail_parts["mail_reply_to"];

$mail_subject = $mail_parts["mail_subject"];

$mail_body = $mail_parts["mail_body"];

$mail_headers = "From: $mail_fromn";
$mail_headers .= "Reply-to: $mail_reply_ton";

$mail_boundary = md5(uniqid(time()));
$mail_headers .= "MIME-Version: 1.0rn";
$mail_headers .= "Content-type: multipart/mixed; boundary="$mail_boundary"rnrn";
$mail_headers .= "This is a multi-part message in MIME format.rnrn";

$report = createReport();
$file = BuildAttachment($report);

$new_body = "--$mail_boundaryrn";
$new_body .= "Content-type:text/plain; charset=us-asciirn";
$new_body .= "Content-transfer-encoding:7bitrnrn";
$new_body .= "$mail_bodyrn";
$new_body .= "--$mail_boundaryrn";

$new_body .= "Content-type:application/pdf; name=report.pdfrn";
$new_body .= "Content-transfer-encoding:base64rnrn";
$new_body .= "$filernrn";
$new_body .= "--$mail_boundary--";
$mail_body = $new_body;

return mail($mail_to,$mail_subject,$mail_body,$mail_headers);

} // function my_mail()

function BuildAttachment($string)

{

set_magic_quotes_runtime(0);

$FileContent = chunk_split(base64_encode($string));

$attachment = $FileContent;

$attachment .="nn";

set_magic_quotes_runtime(get_magic_quotes_gpc());

return $attachment;

} // function BuildAttachment()

function createReport()

{

include 'report.php';

return $report;

} // function createReport()

As for the .pdf file, it is dynamicly created while sending the e-mail based on data from the database etc. Remember, I do get this working nicely on some e-mail programs.
Copy linkTweet thisAlerts:
@PittimannJan 19.2004 — Hi!

Sorry - don't have time for a real analysis. At first sight I would assume, that the prob is caused by "rn" for the linefeeds.

My mailscripts (I have several ones for different purposes) use "n" only and I never faced problems so far.

Of course that is machine specific, but maybe you should give it a try...

Cheers - Pit
Copy linkTweet thisAlerts:
@neumyauthorJan 19.2004 — I ended up so frusterated with this code that I scraped it and found a mail program at SourceForge.net and reworked it until it worked with what I was doing.

I still don't know what I did wrong - I thought everything was perfect - in fact, I don't notice any difference with my new code except positive results.

Thanks for you help!
×

Success!

Help @neumy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...