/    Sign up×
Community /Pin to ProfileBookmark

send e-mail with attachement

I want to add attachements to sending e-mails (.[B]txt[/B] or .[B]sql[/B] files). What should I add/change to headers to could add attachement? ?

[code=php]
<?php

$from = “[email protected]”;
$name = “XX”;
$to = “[email protected]”;
$subject = “DB COPY”;
$HTML = “Copy of daily db.”;

function sendHTMLemail($from,$to,$subject,$HTML)
{
$headers = “From: $fromrn”;
$headers .= “MIME-Version: 1.0rn”;
$boundary = uniqid(“HTMLEMAIL”);
$headers .= “Content-Type: multipart/alternative;”.
“boundary = $boundaryrnrn”;
$headers .= “This is a MIME encoded message.rnrn”;
$headers .= “–$boundaryrn”.
“Content-Type: text/plain; charset=utf-8rn”.
“Content-Transfer-Encoding: base64rnrn”;
$headers .= chunk_split(base64_encode(strip_tags($HTML)));
$headers .= “–$boundaryrn”.
“Content-Type: text/html; charset=utf-8rn”.
“Content-Transfer-Encoding: base64rnrn”;
$headers .= chunk_split(base64_encode($HTML));

if (mail($to,$subject,””,$headers)) {
echo(“<p>Message successfully sent!</p>”);
} else {
echo(“<p>Message delivery failed…</p>”);
}
}

sendHTMLemail($from,$to,$subject,$HTML);

?>
[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@purefanMay 05.2010 — I believe phpmailer has support for attachments, any reason why you want to avoid using it? (sorry, I dont know what to change in the headers)
Copy linkTweet thisAlerts:
@HelleshternauthorMay 05.2010 — I asked about help to add correct header to my code because I need it as is - not php class to sending e-mails.
Copy linkTweet thisAlerts:
@tirnaMay 06.2010 — maybe have a look at this tutorial code that sends attachments with emails to get the info you need.

[URL]http://www.webcheatsheet.com/php/send_email_text_html_attachment.php[/URL]
×

Success!

Help @Helleshtern 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.18,
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,
)...