php html email missing variable data - php

I am sending a php email with script inside an html body. When the message is sent the echo output shown in the script below displays to the screen nicely, but it is missing from the email body received.
How can I include this section in my email?
This is the code I am using
// Put your HTML here
$message = file_get_contents('.message_update.html');
echo $message;
$Date = date('d/m/Y');
$count = 0;
$new_dir = str_replace('_', ' ', $dir);
echo "<font color='blue'>";
echo "The folder name at the website message page is: ",
$new_dir."<br /></font>";
$message .= 'The folder name at the website message page is: ",
$new_dir."<br /></font>';
$comparison = array_diff($list2, $list1);
foreach ($comparison as $line) {
echo "Date Update: ", $Date, " : To listen to the ", ++$count, "
message click the picture
here ";
echo '<a href="' . $folder_path, $line . '"><img align="top"
width="100" height="20" text-
align: center;
src="https://nerjabible.com/images/audio_player1.png" /></a>';
echo ", The ", $count, " message name is entitled: ", $line. "
<br />";
}
$message = file_get_contents('.message_update1.html');
echo $message;
// Mail it`
`
The output of the first html file .message_update.html is included in top of the email received.
Then the variables from the script are missing
The output of the second .message_update1.html is included at the bottom of the email received.
How can I wrap this section
$new_dir = str_replace('_', ' ', $dir);
echo "<font color='blue'>";
echo "The folder name at the website message page is: ",
$new_dir."<br /></font>";
$message .= 'The folder name at the website message page is: ",
$new_dir."<br /></font>';
$comparison = array_diff($list2, $list1);
foreach ($comparison as $line) {
echo "Date Update: ", $Date, " : To listen to the ", ++$count, "
message click the picture
here ";
echo '<a href="' . $folder_path, $line . '"><img align="top"
width="100" height="20" text-
align: center;
src="https://nerjabible.com/images/audio_player1.png" /></a>';
echo ", The ", $count, " message name is entitled: ", $line. "
<br />";
}
and include it in the $message variable?

Related

Getting random Blank email while using nested while loop

1st, I know mysql_ is outdated and I should use mysqli (unfortunatly, I inherited this system and its way too much work to change it over at the present time)
The problem I have is when I execute the code, I am getting random blank emails. This system loops through a list of stores in a database and lists the information in a table for the store managers. It doesnt really matter what information is being presented. Does anyone see anything right off hand that micht cause this problem?
while($store = mysql_fetch_array($result_store)){
#Updates the Report Date for each store in the Loop
$report_date = "UPDATE ActiveStores SET Report_Date = '$Today' WHERE StoreNumber = $store[StoreNumber]";
if (!mysql_query($report_date, $con)){
die('Error: ' . mysql_error());
}
#Selects data from ActiveStores for the current store in the loop
$result2 = mysql_query("SELECT * FROM ActiveStores WHERE StoreNumber = '$store[StoreNumber]' ORDER BY StoreNumber");
#Loops through the currently selected store and Creates an Array of the data
while ($row = mysql_fetch_array($result2)) {
#Sets Store Variable
$Store = $row['StoreNumber'];
echo '<table width="1110"><table width="1102"><tr>';
# To Email Address
#$emailaddress = '******#*****.com';
# Message Subject
$emailsubject= 'Testing Report - Store: ' . $Store;
#Turn on Output buffer for email
ob_start();
#Heading for Report
echo '<h2 class="blktext">Walgreens Weekly Report - ' . $Today . '<br /></h2>';
echo '<h2>Insurance Orders:</h2>';
#Cancelled Orders for the store this week
$result_cash_canceled = mysql_query("SELECT * FROM Orders WHERE StoreNumber = '$Store' AND Cancel = 'checked' AND Order_Type = 'Cash' AND Cancel_Date > '$Sevendaysback'");
$tot_ord_ins_prt = mysql_num_rows($result_cash_canceled);
if ($tot_ord_ins_prt !== 0){
echo '<h4 class="blktext">Cancelled Orders for the store this week</h4><span class="blktext">';
echo '<p><i>Fitter Action: Fitter to contact client to notify of cancelled order, if not initialed by client.</i></p>';
echo "<table border='4' class='rpttbl' frame='hsides' rules='rows' width='1400'>";
echo '<tr><th>Store #</th><th>Order #</th><th>Customer</th><th>Phone #</th><th>Cancel Date</th width="150"><th>Reason for Cancellation</th><th width = "150">Patient Notified<th></tr>';
while($row_cash_canceled = mysql_fetch_array($result_cash_canceled)){
echo "<tr>";
echo "<td align='center'>" . $row_cash_canceled['StoreNumber'] . "</td>";
echo "<td align='center'>" . $row_cash_canceled['Order_ID'] . "</td>";
echo "<td align='center'>" . $row_cash_canceled['Cust_First_Name'] . " " . $row_bo['Cust_Last_Name'] . "</td>";
echo "<td align='center'>" . $row_cash_canceled['Cust_Phone'] . "</td>";
echo "<td align='center'>" . $row_cash_canceled['Cancel_Date'] . "</td>";
echo "<td align='center'> </td>";
echo "<td align='left'>( ) Called: Patient Cancelled notified<br />( ) Called: LVM for Patient</td>";
echo "</tr>";
}
echo "</table>";
echo "Total: " . $tot_ord_ins_prt;
echo'</span>';
}
#Message at bottom of email
echo '<br /><br /><br /><br /><p>Thank you for your prompt attention to this report.</p>';
echo '<p>If this report is blank in all the above sections, this means, at this point, we are not showing any active orders within our system.<br />';
echo 'If you feel this is in error, please contact our Customer Care team at: <strong>(***) ***-8125</strong></p>';
echo '<p>Please update this form with the appropriate action taken by patient, and fax back to: (866) 8**-**** OR email to: ******#*****.com</p>';
echo '<p>Fitter Name: ________________________________________</p>';
echo '<p>Comments: _______________________________________________________________<br />';
echo '_________________________________________________________________________</p>';
echo '<p>The information contained in this email, together with any attachments, is intended only for the use of the individual or entity<br /> to which it is addressed. It may contain information that is confidential and prohibited from disclosure. If you are not the intended <br />';
echo 'recipient, you are hereby notified that any dissemination, or copying, of this message or any attachment is strictly prohibited.</br> If you have received this message<br /> in error, please notify the original sender immediately by phone or by return email, </br>';
echo 'and delete this email, along with any attachments. <br />Receipt by anyone other than the intended recipient is not</br> a waiver of any privileged information. </p>';
}
$body=ob_get_contents();
ob_end_clean();
#$body = "** It is Imperative that you respond to this email. When you receive this please print it out, sign your name and store number and fax the form to ***-***-1161**<br /><br /><br />";
#$body .= "Name: <br /><br />Store #:";
$headers = 'From: Visual Footcare Technologies *****#****.com'.$eol;
$headers .= 'Reply-To: Visual Footcare Technologies *****#*****.com'.$eol;
$headers .= 'Return-Path: Visual Footcare Technologies <mcooper#visualfootcare.com>'.$eol; // these two to set reply address
#$headers .= 'Cc: ******#*****.com'.$eol;
$headers .= "Message-ID:<".$now." TheSystem#".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
$msg .= "Content-Type: multipart/alternative".$eol;
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;
$msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection.
then a standard mail(......) code to send the email and then ending the loop.
hope that makes sense.
try changing this
if ($tot_ord_ins_prt !== 0)
to
if ($tot_ord_ins_prt !== false)
MIME header blocks must be terminated by a blank line, even when used in a multi-part section. I don't know what you mean by "random", but I suspect that "blank emails" could be the result of your message body being interpreted as invalid MIME headers.
Insert a blank line between the last MIME header and your message body:
$msg .= $eol.$body.$eol.$eol;
If this doesn't help, you should probably show that "standard" mail line you mentioned. Since it's the one that actually sends the email, I'm surprised you didn't include it. You included a whole lot of other code. It would be good to see what you do with the two strings, $headers and $msg.

joomla getMailer() not working as expected

im trying to use joomla mailer to send emails but it doesent work, any suggestions? what am i missing? i've searched around the web and SO, but it didnt help.
the only error i get is 500, and i cant understand why...
this is the actual code:
<?php
//framework joomla
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__) . "/../"));
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
$mainframe =& JFactory::getApplication('site');
//get vars
$session =& JFactory::getSession();
$num1 = $session->get('variable1');
$num2 = $session->get('variable2');
$val= $session->get('variable3');
$uq= $session->get('unique');
$sendto= $session->get('mail');
//mail
$mailer =& JFactory::getMailer();
$mailer->setSender('some1#domain.com');
$recipient = array($sendto, 'some1else#domain.com');
$mailer->addRecipient($recipient);
$body = '<h2>sometext</h2>'
. '<div>sometext</div>'
. '<div> blabla' echo $num1 'blabla </div>'
. '<div> texttext' echo $num2 'texet </div>'
. '<div> texttext' echo $val 'text </div>';
$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setBody($body);
$mailer->AddEmbeddedImage("$uq".".gif", "image_0", "", "base64", "image/gif");
$mailer->addAttachment("$uq".".gif");
//send
$send =& $mailer->Send();
if ( $send !== true ) {
//Elimina .gif
$mask = "*.gif";
array_map( "unlink", glob( $mask ) );
unset($mailer);
echo 'error: ' . $send->message;
} else {
unset($mailer);
//Elimina .gif
$mask = "*.gif";
array_map( "unlink", glob( $mask ) );
echo 'done';
}
?>
forgot to add specs about the platform:
PHP Version 5.3.22
Joomla! Version 2.5.9
if you need any other info just ask.
update:
i tried another joomla! version, a simplified version of the code without variables and with a single email, plain text emails... nothing seems to work.
internal server error (500) with a blank error log... (wierd, but the installation it's inside a subdirectory with many other installation, and my webhosting allow me to see only the "root" log, so i think this is the problem of the blank error log...)
Not quite sure whether this is the root of your problem. But $mail->setSender() accepts an array. Example : $mail->setSender(array('SENDER EMAIL', 'SENDER NAME'));
AND
$mail->addRecipient() accepts a string OR an array. Use an array if you are sending the email to multiple recipients and the string when you are sending the email to only 1 recipient.
Hope this helps
ok, solved!
this might help someone else so, here is how:
$config =& JFactory::getConfig();
this line grabs the email configuration of Joomla, without this Jmail will not send emails.
//body email
$body .= "<h2>Texttext</h2>" . "\n";
$body .= "<div>TexttextTexttextTexttext" . $blockh . " Texttext " . $blockd . "\n";
$body .= "<div> TexttextTexttext <span> " . $num1 . " </span> Texttext </div>" . "\n";
$body .= "<div>TexttextTexttextTexttext <span> " . $val . " </span> Texttext </div>";
previus concatenation of the body was not working, it seems that double quotes are needed to work...
$mailer->isHTML();
the "true" inside is not necessary since true is the default value..
In answer to KentaS comment of
previus concatenation of the body was not working, it seems that double quotes are needed to work...
It has nothing to do with single or double quotes.
In your original post you had:
$body = '<h2>sometext</h2>'
. '<div>sometext</div>'
. '<div> blabla' echo $num1 'blabla </div>'
. '<div> texttext' echo $num2 'texet </div>'
. '<div> texttext' echo $val 'text </div>';
the part:
'<div> blabla' echo $num1 'blabla </div>'
causes a syntax error (string, followed, without concatenation, by a call to "echo", followed, without concatenation, by a string...!
Somthing which works with single quotes:
$body = '<h2>sometext</h2>'
. '<div>sometext</div>'
. '<div> blabla' . $num1 . 'blabla </div>'
. '<div> texttext' . $num2 . 'texet </div>'
. '<div> texttext' . $val . 'text </div>';
And with double quotes you can do even shorter:
$body = "<h2>sometext</h2>"
. "<div>sometext</div>"
. "<div> blabla $num1 blabla </div>"
. "<div> texttext $num2 texet </div>"
. "<div> texttext $val text </div>";
Cheers,
Dom

Difficulty in moving temp files with php after uploading them and renaming

I have a form for uploading files to a web server and then saving the filepath along with the email address it's connected to and a serial code to a sql table. The problem is, what if someone uploads a file with the same name as a previous person or upload? To fix this, I want to name the file "insert serial code here".mp4 or .pdf. When I do this it comes up with the following error:
Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in /home/content/98/10339998/html/scripts/upload.php on line 57
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php7UzcdG' to '../story_files/' in /home/content/98/10339998/html/scripts/upload.php on line 57
Stored in: ../story_files/
Here is a full echo example:
Customer's unique serial code: d0d74-ef227
Upload:
Type: application/pdf
Size: 14.4287109375 kB
Temp file: /tmp/php7UzcdG
Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in /home/content/98/10339998/html/scripts/upload.php on line 57
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php7UzcdG' to '../story_files/' in /home/content/98/10339998/html/scripts/upload.php on line 57
Stored in: ../story_files/
../story_files/
Upload: file.mp4
Type: video/mp4
Size: 374.6396484375 kB
Temp file: /tmp/phpQczVLm
file.mp4 already exists.
Serial Code Emailed to Customer Michael
Here is the code, note the difference between the video and story part of it, I didn't convert the video part yet it is the fully-working original code. Also, PHP thinks that the serial code is a filepath, why is that? The code is simply a 10 digit series of letters and numbers two sets of 5 digits with a dash between to simplify reading it.
<title>Uploading Files and Sending Serial Code To Customer</title>
<!--Favicon Code-->
<link rel="shortcut icon" type="image/x-icon" href="../images/favicon.ico" />
<!--Favicon Code-->
<link href="/CSS/CSS.css" rel="stylesheet" type="text/css" />
<div align="center">
<p><span class="linkText">Home Contact Us Products</span> </p>
<p> </p>
<h2 class="headingText"><img src="/images/banner.jpg" alt="legendmaker - makes legends: banner" width="297" height="473"></h2>
<h2 class="headingText"> </h2>
<h2 class="headingText">Upload Story Files</h2>
</div>
<?php
// before we do anything make sure there is a correct password (we don't want unauthorized usage)
$password = trim($_POST['password']);
if ("*****" == $password)// not going to post my pass on the forums :P
{
///// generate unique serial code ///////////////////////////////////////////////////////////////
$string1 = substr(md5(uniqid(rand(), true)), -5, 5);
$string2 = substr(md5(uniqid(rand(), true)), -5, 5);
$serial = sprintf('%s-%s', $string1, $string2);
echo "Customer's unique serial code: ";
echo $serial;
echo " ";
/////end of generate unique serial code ///////////////////////////////////////////////////////////////
///story file upload///////////////////////////////////////////////////////////////////////////////////
if ($_FILES["file"]["size"])
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "<br>" . "<br>" . "<br>" . "Upload: " . $_FILES["file"]["$code"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("stories/" . $_FILES["file"]["$code"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"../story_files/" . $_FILES["file"]["code"]);
echo "Stored in: " . "../story_files/" . $_FILES["file"]["$code"] . "<br>";
$storyPath = sprintf("../story_files/" . $_FILES["file"]["$code"]);
echo $storyPath;
}
}
}
else
{
echo "No story file was chosen, this is not an error just a notification. Any other files selected will still upload correctly. ";
}
///video file upload////////////////////////////////////////////////////////////////////////////////
if ($_FILES["videoFile"]["size"])
{
if ($_FILES["videoFile"]["error"] > 0)
{
echo "Return Code: " . $_FILES["videoFile"]["error"] . "<br>";
}
else
{
echo "<br>" . "<br>" ."Upload: " . $_FILES["videoFile"]["name"] . "<br>";
echo "Type: " . $_FILES["videoFile"]["type"] . "<br>";
echo "Size: " . ($_FILES["videoFile"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["videoFile"]["tmp_name"] . "<br>";
if (file_exists("../video_files/" . $_FILES["videoFile"]["name"]))
{
echo $_FILES["videoFile"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["videoFile"]["tmp_name"],
"../video_files/" . $_FILES["videoFile"]["name"]);
echo "Stored in: " . "../video_files/" . $_FILES["videoFile"]["name"] . "<br>";
$videoPath = sprintf("../video_files/" . $_FILES["file"]["name"]);
echo $videoPath;
}
}
}
else
{
echo "No video file was chosen, this is not an error just a notification. Any other files selected will still upload correctly. ";
}
/// submit information to database/////////////////////////////////////////////////////////////////////
$username="storycodes";
$password="Legendmaker1!";
$con = mysqli_connect("storycodes.db.10339998.hostedresource.com",$username,$password);
if (!$con)
{
die('Could not connect: ' . mysqli_error());
}
$email = $_POST['email'] ;
$submitInformation = "INSERT INTO `storycodes`.`storycodes` (`code`, `email`, `video`, `story`) VALUES ('$serial', '$email', '$videoPath', '$storyPath');";
mysqli_query($con, $submitInformation); // submits information to database for later recollection
////////////////////end of submit to database///////////////////////////////////////////////////////////
/////////////////// email the code to customer//////////////////////////////////////////////////////////
require_once '../PHPMailer_5.2.2/class.phpmailer.php';
$name = $_POST['name'] ;
$body = "Thank you for using legendmaker $name! Your story has been completed and will now be accesible at www.thelegendmaker.net/stories.html On that page you will be required to enter a serial code in order to access your files. We require a serial code in order to access files because we care about our customers and security is a concern. Your serial code is: $serial";
$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
try
{
$mail->AddAddress($email, $name);
$mail->SetFrom('fakeemail1#gmail.com', 'Sender Name');
$mail->AddReplyTo('fakeperson#yahoo.com', 'Fake Name');
$mail->Subject = "Message From Legendmaker: $name your story is now complete.";
$mail->Body = $body;
$mail->Send();
echo "<br>" . "<br>" . "Serial Code Emailed to Customer $name</p>\n";
echo "<img src='/images/knight-success.png' alt='success' width='429' height='791' />";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
/////////////////// end of email code///////////////////////////////////////////////////////////////////
}
else
{
echo "incorrect password";
}
/// end of file uploads//////////////////////////////////////////////////////////////////////////
?>
<link href="/CSS/CSS.css" rel="stylesheet" type="text/css" />
<p>
<!--google cart code ------------------------------------>
<script id='googlecart-script' type='text/javascript' src='https://checkout.google.com/seller/gsc/v2_2/cart.js?mid=215313740482542' integration='jscart-wizard' post-cart-to-sandbox='false' currency='USD' productWeightUnits='LB'></script>
</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p align="center">Contact Us Site Owner Upload Service Agreement</p>
You use $_FILES["file"]["code"] instead of $_FILES["file"]["name"] for the file name which doesn't exist so the result is that you're passing a directory as the second argument.
move_uploaded_file($_FILES["file"]["tmp_name"],
"../story_files/" . basename($_FILES["file"]["name"]));
EDIT
if you want to use the serial code that is generated to be the file name just concatenate it to the directory string in move_uploaded_file
move_uploaded_file($_FILES["file"]["tmp_name"],
"../story_files/" . $serial);

Adding embedded images within mail body phpmailer class

Im trying to embed an image within my message body but it ends up as an attachment
$mailer->Subject = APP_NAME . " - " . $name . " send you and Ad : " . $row['name'];
$mailer->IsHTML(true);
$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDimes.png');
//footer
$footer = "Regards<br/><br/>";
$footer .= '<table style="width: 95%">';
$footer .= '<tr>';
$footer .= '<td>';
$footer .= "<strong><span style='font-size: 15px'>NamDimes Team</span></strong><br/>
NamDimes<br/>
Contact Number: " . APP_CONTACT . "<br/>
Email: " . APP_EMAIL . "<br/>
Website: " . APP_WEBSITE . "<br/>";
$footer .= '</td>';
$footer .= '<td style="text-align:right">';
$footer .= '<img src=\"cid:logoimg\" />';
$footer .= '</td>';
$footer .= '</tr>';
$footer .= '</table>';
$mailer->Body = $body . $footer;
$mailer->AltBody="This is text only alternative body.";
$mailer->AddAttachment('../' . $row['image_path'], $row['name'] . ".jpg");
i have set everything else, including the addresses, the mail gets send out, logo image that I want embed in the body gets attached as an attachment, anyone know why?
Don't use $mailer->AddEmbeddedImage, but directly add
<img src="http://.../images/namDiams.png" /> instead.
The mail length should be lighter... And it works.
EDIT
I don't know if it will help you but there is a little mistake here :
$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDimes.png');
Should be
$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDiames.png');//the last param the second 'a' was missing...
Another topic here
I can confirm that user2189925's answer does work. However, I use the absolute path since the location of the calling script is more likely to change than the location of the image.
e.g.
<img src="C:\folder\images\namDiames.png" />
Faced the same problem, then I decided to replace the following
<img src="img/example.jpg"
with
<img src= "https://mysitename.com/img/example.jpg">
and it worked.
just give path of your image to the mail body eg: (img src="../images/cat.jpeg) it will definately work

can't get loop in mysql_fetch_array to print on separate lines

I am trying to loop through my mysql query result and print out some of the data. What I expected was when I added "\n" to the end of the print message, it would print each message on a separate line. But for some reason its all on one line. Why is this and how can I make each message be on a separate line?
while($row = mysql_fetch_array($result))
{
$message = $row['action_type'] . " " . $row['identifier'] . " # " . " placeholder ";
if($row['location'] !== NULL)
{
$message += " on " . $row['location'] . "\n";
}
echo $message . "\n";
}
Your $message variable is ending with a /n when it should be \n. Try updating it to fix (unless of course, in that section of the code it's on purpose):
$message += " on " . $row['location'] . "\n";
The actual echo statement ends with a real newline, so this should work properly in a command-line, but not in a browser.
To get it to display on a new line in a browser, change the \n instances to <br />:
echo $message . "<br />";

Categories