0

I'm trying to send an e-mail using the PHP mail function and having two issues in regard to the below code:

1) When I get the e-mail - it is not formatted in HTML - instead I get just the actual HTML code in the e-mail - I get all e-mail via HTML by default so it doesn't appear to be a local setting.

2) I want to display in the e-mail the $img which is the image that someone has uploaded. However is my synatx correct on this line in order to concat the URL so it's formulated with the image held in $img:
$mailimg = '<img src="http://www.mysite.com/custom_images/images/".= $img"></a>';

<?php
$to ="mysite@z.net";
$from = $_POST['from']; 
$msg = $_POST['msg'];
$img = $_REQUEST['show_image'];
//Image in e-mail
$mailimg = '<img src="http://www.mysite.com/custom_images/images/".= $img"></a>';
//Mail Body - Position, background, font color, font size...
$body ='
<html>
<head>
<style>
<!--
body, P.msoNormal, LI.msoNormal
{
background-position: top;
background-color: #336699;
margin-left:  10em;
margin-top: 1em;
font-family: "verdana";
font-size:   10pt;
font-weight:bold ;
color:    "000000";
}
-->
</style>
</head>
</body>';
//To send HTML mail, the Content-type header must be set:
$headers='MIME-Version: 1.0n' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: System Admin <mysite@z.net>' . "\r\n";
$bodys .= "A image has just been uploaded for viewing<br>";
$bodys .= "$mailimg";
$subject .="Custom Image";
$body = $body . $bodys;
mail($to, $from, $subject, $body, $headers);
?>
2
Contributors
4
Replies
27
Views
2 Years
Discussion Span
Last Post by koneill
0

Dispite other errors in the code, mail() needs the following parameters:

to, subject, message (, headers etc.) (See here)

No from. So this will cause a problem.

Your HTML is invalid, as you are closing the body tag, and then placing the content, and not closing it and the HTML tag off. Change line 28 to <body>, and add to line 36 $body . $bodys . "</body></html>";.

Line 7 should be: $mailimg = '<a href="http://google.com/"><img src="http://www.mysite.com/custom_images/images/'.$img.'"></a>'; assuming that $img is something like "home.jpg" etc.

0

Awesome - Is there a way I can get the from into the php e-mail?>

Also - now I'm getting the e-mail but it's totally blank - the $img is just as you stated a home.jpg etc.

I did add a '; to the body tag because without it - I get a parase error: Parse error: syntax error, unexpected T_STRING in /usr/www/users/aaa/custom_images/mail.php on line 30

<?php
$to ="mysite@z.net";
$from = $_POST['from']; 
$msg = $_POST['msg'];
$img = $_REQUEST['show_image'];
//Image in e-mail
$mailimg = '<a href="http://www.mysite.com/"><img src="http://www.mysite.com/custom_images/images/'.$img.'"></a>';
//Mail Body - Position, background, font color, font size...
$body ='
<html>
<head>
<style>
<!--
body, P.msoNormal, LI.msoNormal
{
background-position: top;
background-color: #336699;
margin-left:  10em;
margin-top: 1em;
font-family: "verdana";
font-size:   10pt;
font-weight:bold ;
color:    "000000";
}
-->
</style>
</head>
<body>';
//To send HTML mail, the Content-type header must be set:
$headers='MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: System Admin <mysite@z.net>' . "\r\n";
$bodys .= "A custom image has just been uploaded<br>";
$bodys .= "$mailimg";
$subject .="Custom Image";
$body . $bodys . "</body></html>";
mail($to, $subject, $body, $headers);
?>
0

You need to make $body equal it's new value. That explains why theres no content coming through, because $bodys isn't actually placed into the mail().

$body .= $bodys . "</body></html>";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.