/    Sign up×
Community /Pin to ProfileBookmark

Sending HTML mail via PHP

I’m having a bit of an issue with this one.

I can get PHP to send me an email from the “FROM:” I insert without any trouble.
I can get PHP to send me an HTML mail, but it does not show the proper “FROM:” field.

I cannot get it to do both. It will do either/or.
Here is my code:

[SIZE=”5″][FONT=”Arial Black”][COLOR=”Red”]This script sends an email – but not an HTML email.[/COLOR][/FONT][/SIZE]
Form is on Page One:

[code=php]
<body bgcolor=”#000000″>

<p><span class=”style2″><br>

<form method=”post” action=”sendemail2.php”>

<br>

<table width=”435″ border=”0″>
<tr>
<td width=”228″><div align=”right”><span class=”style2″>Email will be sent from: </span></div></td>
<td width=”179″><input name=”email” type=”text”></td>
</tr>
<tr>
<td><div align=”right”><span class=”style2″>Email will be sent to: </span></div></td>
<td><input name=”email2″ type=”text”></td>
</tr>
<tr>
<td><div align=”right”><span class=”style2″>Subject:</span></div></td>
<td><input name=”subject” type=”text”></td>
</tr>
</table>
<br>
<span class=”style2″>Message:</span><br>
<textarea name=”message” rows=”15″ cols=”70″></textarea><br>
<input type=”submit” value=”Send Email”>
</form>
</body>
[/code]

Here is the PHP page:

[code=php]
<?php
$to = $_REQUEST[’email2′] ;
$subject = $_REQUEST[‘subject’] ;
$email = $_REQUEST[’email’] ;
$message = $_REQUEST[‘message’] ;
$headers = “From: $emailrn” .
“X-Mailer: php”;
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print “Your mail was sent successfully”; }
else
{print “We encountered an error sending your mail”; }
?>
[/code]

[SIZE=”5″][FONT=”Arial Black”][COLOR=”Red”]This script sends an HTML email – but does not display the “From:” address properly.[/COLOR][/FONT][/SIZE]
Form Page:

[code=php]
<form method=”post” action=”sendhtmlmail2.php”>

<br>

<table width=”435″ border=”0″>
<tr>
<td width=”228″><div align=”right”><span class=”style2″>Email will be sent from: </span></div></td>
<td width=”179″><input name=”from” type=”text”></td>
</tr>
<tr>
<td><div align=”right”><span class=”style2″>Email will be sent to: </span></div></td>
<td><input name=”to” type=”text”></td>
</tr>
<tr>
<td><div align=”right”><span class=”style2″>Subject:</span></div></td>
<td><input name=”subject” type=”text”></td>
</tr>
</table>
<br>
<span class=”style2″>Message:</span><br>
<textarea name=”message” rows=”15″ cols=”70″></textarea><br>
<input type=”submit” value=”Send Email”>
</form>
[/code]

PHP Script page:

[code=php]
<?php
$to = $_REQUEST[‘to’] ;
$subject = $_REQUEST[‘subject’] ;
$from = $_REQUEST[‘from’] ;

$message = “<html><head></head><body bgcolor=”red”><center><font size=”+2″>Test</font><BR><p>Wow, I sent an HTML Mail!</p></body></html>”;
$headers = “Content-type: text/html; charset=iso-8859-1rn”;
$headers .= “From: $fromrn”;
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print “Your mail was sent successfully”; }
else
{print “We encountered an error sending your mail”; }
?>
[/code]

I have not been able to send an HTML mail from the “From:” address I want to use.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 22.2008 — [B][SIZE="6"][COLOR="Red"]You left out some back-slashes.[/COLOR][/SIZE][/B]
<i>
</i>$headers = "Content-type: text/html; charset=iso-8859-1[color=red][/color]r[color=red][/color]n";
Copy linkTweet thisAlerts:
@sstalderJul 22.2008 — Try switching your headers around:

$headers = "From: $fromrn";

$headers .= "Content-type: text/html; charset=iso-8859-1rn";

Once again, trumped by the dog... ?
Copy linkTweet thisAlerts:
@ask21900Jul 22.2008 — You forgot to escape your nr...


EDIT: lol... I guess that's what I get for testing before I posted, and not refreshing...

WOW! 11,329 posts? Do you ever sleep?
Copy linkTweet thisAlerts:
@NogDogJul 22.2008 — You forgot to escape your nr...


EDIT: lol... I guess that's what I get for testing before I posted, and not refreshing...

WOW! 11,329 posts? Do you ever sleep?[/QUOTE]

Nope.

(Would you believe my posting rate here is greatly reduced from what it used to be?)
×

Success!

Help @donatello 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.17,
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,
)...