/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] php mail function

Hi there, I’m currently in the process of revising the contents of a newsletter that is generated from a PHP script. I’m using a multipart/alternative MIME type. It was working fine before, but suddenly it is not showing up correctly when being sent. It just show the entire code. So I end up getting the mime information and both the plain and html message (with source code showing) displayed when the email is sent.

[CODE]–Multiparta09988018a
Content-Type: text/plain; charset=”utf-8″

….. Information that doesn’t matter …..

–Multiparta09988018a
Content-Type: text/html; charset=”utf-8″

<html>
<head>
<style type=”text/css”>
….. css stlyes …..
</script>
</head>
<body>
….. Information that doesn’t matter …..
</body>
</html>

–Multiparta09988018a–
[/CODE]

[code=php]//set boundary
$boundary = “Multipart” . substr(md5(date(“c”)),0,10);
//set headers and subject
$headers = “From: …@….comrnReply-To: …@….comrnMIME-Version: 1.0rnContent-Type: multipart/alternative; boundary=” . $boundary . “rn”;
//set body
$body = “–$boundaryrnContent-Type: text/plain; charset=”utf-8″rn
$bodyTextrn
–$boundaryrnContent-Type: text/html; charset=”utf-8″rn
$bodyHTMLrn
–$boundary–rn”;
//mail
mail($to,$subject,$body,$headers);[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 25.2011 — Do you see what appears to be any extra space around the boundaries in the received email? My understanding is that some sendmail programs convert "n" characters to the "rn" combination. Therefore, since you are (normally correctly) using "rn" for your header/boundary separators, it *might* now be converting them to "rrn" and screwing things up. So while I frankly think it's unlikely, it might still be worth a try to change your separators to "n" and see if that helps -- especially if nobody comes up with anything better. ? (It might be a good idea to make it a variable, so you can change it in one place when you experiment and likely have to change it back.)
Copy linkTweet thisAlerts:
@iamanubcakeauthorFeb 25.2011 — I tried doing that and didn't seem to work. I'm really not sure why I'm having this issue. I had a similar issue before and I don't remember how I fixed it. I've decided to try using an output buffer because some tutorials on how to send mime-type emails show you to do that. Even with that I'm getting issues. It's showing the boundary and the content-type declaration on the same line and not adding the line break. Literally any suggestion works for me. Even if it means overhauling my code.
Copy linkTweet thisAlerts:
@NogDogFeb 25.2011 — Only other thing I can suggest -- since I can't claim to me an email expert -- is to do what I do: use PHPMailer to put it all together and send it. ? Here's an example of a multipart email: http://phpmailer.worxware.com/index.php?pg=exampleamail
Copy linkTweet thisAlerts:
@iamanubcakeauthorFeb 25.2011 — When I examine the headers of the email through Outlook it doesn't show the "Content-Type: multipart/alternative. Could I be inserting that into the message wrong?
Copy linkTweet thisAlerts:
@iamanubcakeauthorFeb 25.2011 — Nevermind, I think I found the issue. I have the script send an email report after it sends the regular message, but I have it set the headers for the report before it sends the actual email. The report is a plain/text email so I didn't put any content-type data in the headers. Hence the reason the email wasn't displaying properly. Thanks for your help though!
×

Success!

Help @iamanubcake 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.14,
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,
)...