/    Sign up×
Community /Pin to ProfileBookmark

How to send an HTML email with images using PHP’s mail()

I’m trying to create a page where the user can create an HTML newsletter and email it to recipients. It looks like this:
[url]http://www.jaggednighttheatre.com/admin/newsletter.php[/url]

I got it to send an HTML email with text and forms but it won’t send an image for some reason. I need it to send images. Here’s my PHP code:

[CODE]
if(isset($_POST[‘submitted’]))
{
$title = mysqli_real_escape_string($dbc, trim($_POST[‘title’]));
$date = trim($_POST[‘date’]);
$body = mysqli_real_escape_string($dbc, trim($_POST[‘body’]));

$letter = ”;
$letter = ‘<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>’;
$letter .= ‘<html xmlns=”http://www.w3.org/1999/xhtml”>’;
$letter .= ‘<body>’;
$letter .= $body;
$letter .= ‘</body>’;
$letter .= ‘</html>’;

$to = ‘[email protected]’;
$subject = ‘Jagged Night Theatre’;
$headers = “From: [email protected]”;
$headers .= “Content-Type: text/html; charset=ISO-8859-1rn”;

mail($to, $subject, $letter, $headers);
}
[/CODE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@donatelloAug 24.2011 — I have this script somewhere, it sends the email via PHP...

Sites like this have been abused badly, so be careful. Spammers will hijack it in a heartbeat.

MailChimp used to have this as a feature where you could choose a template and then just send it using PHPmail, but they have disabled this feature.

I can only guess why, but will assume that in this world of mail server hijackers and spammers, such a service would be quickly hijacked.

I'll see if I can dig up my scripts and post them for you...

In the meantime, go and visit http://www.mailchimp.com for some more good ideas...

?
×

Success!

Help @mikeglaz 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 6.1,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...