So, I'm kind of in a rut for over a day now because of this issue. I have a PHP wherein it gets called by Cron on a set amount. It gets called and executes just fine without much problems except for the styling. What it does is query the database on a set time for a value and if it's true then it proceeds to email that to the designated email that I put in the script. It's doing it's job but the problem is the format when the email gets delivered. The email looks like this when I open it:
The issue, as you can see is that only the first line or row gets formatted on the table and the rest of the results doesn't follow it.
Here's the current script I'm using with some omitted/changed details.
#!/path/to/php
<?php
//DB
$dbconnect=new mysqli('localhost', 'user', 'pass', 'db');
$result=$dbconnect->query("SELECT `uid`,`pid`,`pdesc`,`umail`,`name` FROM `db_table` WHERE `pid`<='6'");
//if there are any records matching this query send an email listing each one using 'uid' as the identifier
if($result->num_rows>=1) {
$to = 'test#test.com';
$subject = "TEST FOR PRIZES NOTIFICATION";
$headers = 'From: sender#test.com' . "\r\n" .
$headers = "MIME-Version: 1.0" . "\r\n" .
$headers = "Content-type:text/html;charset=iso-8859-1" . "\r\n" .
'Reply-To: rep#test.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = '<html><body>';
$message .= 'THIS IS A TEST!';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= '<tr>
<td>User ID</td>
<td>Display Name</td>
<td>Email</td>
<td>Price</td>
<td>Price Description</td></tr>';
while($row=$result->fetch_assoc()) {
$message .= "<tr><td>".$row['uid']."</td>";
$message .= "<td>".$row['name']."</td>";
$message .= "<td>".$row['umail']."</td>";
$message .= "<td>".$row['pid']."</td>";
$message .= "<td>".$row['pdesc']."</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
}
if(mail($to, $subject, $message, $headers)) {
//mail successfully sent
} else {
//mail unsuccessful
}
}
?>
Thank you for your time!
You're closing the table inside of your loop, so it's closed after the first entry. Change your code from this:
while($row=$result->fetch_assoc()) {
$message .= "<tr><td>".$row['uid']."</td>";
$message .= "<td>".$row['name']."</td>";
$message .= "<td>".$row['umail']."</td>";
$message .= "<td>".$row['pid']."</td>";
$message .= "<td>".$row['pdesc']."</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
}
to this:
while($row=$result->fetch_assoc()) {
$message .= "<tr><td>".$row['uid']."</td>";
$message .= "<td>".$row['name']."</td>";
$message .= "<td>".$row['umail']."</td>";
$message .= "<td>".$row['pid']."</td>";
$message .= "<td>".$row['pdesc']."</td></tr>";
}
$message .= "</table>";
$message .= "</body></html>";
to close the table at the end.
Related
Hello fellow citizens of ....oh skip all that... I am experiencing some difficulty trying to output html via my cron and I have checked other responses to this issue. But, I can’t seem to get it right so I’m hoping someone out there can assist me. The data pulls correctly and the cron email sends but what I end up with is my data with all the html tags appended. I have tried moving the $to and $header out of the while loop, above the while loop, below the while loop, and also tried with everything inside the while loop with only the $message being the one call to dtat $row etc and then echo'd that from within the loop.
I have tried two versions of ---
( $headers .= 'Content-type:text/html;charset=iso-8859-1'
. "\r\n";)
and
( $headers .= 'Content-type:text/html;charset=utf-8-1' .
"\r\n";)
So any assistance would be great!
Cheers!
$db = new MySQLi('------', '------', '------', '------');
if ($db->connect_error) {
$mese = $db->connect_error; } else {
$sql = "SELECT * FROM table";
$result = $db->query($sql);
while ($row = mysqli_fetch_assoc($result)) {
$to = "some#gmail.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type:text/html;charset=iso-8859-
1'
. "\r\n";
$message = "<html>";
$message .= "<head></head>";
$message .= "<body>";
$message .= '<ul><li>' . $row['item'] .'</li></ul>';
echo $message;
$message .= "</body>";
$message = "</html>";
$from = "somewhere#.someplace.net"; $subject = "checking php
mail";
mail($headers, $to,$subject,$message, $from);
}
}
?>
All the quotes in your code are messed up. This could be the reason.
Try this:
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html>';
$message .= '<head></head>';
$message .= '<body>';
$message .= '<ul><li>' . $row['item'] .'</li></ul>';
$message .= '</body>';
$message .= '</html>';
I want to send to mail to user for any update.
My first tried as below, here all mail goes to spam folder but here sender name display well.
This code is
$headers = "From: Sender Name <info#senderweb.com >\r\n" .
"Reply-To: info# senderweb.com\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'MIME-Version: 1.0' . "\r\n";
After prevent goes to spam folder, my below code make all mail goes well at inbox but here sender name display server name something like senderwe#server1.server.com.
I found this report at track delivary of cpanel : ECDHE-RSA-AES128-GCM-SHA256:128 CV=yes: SMTP error from remote mail server after MAIL FROM:< senderwe#server1.server.com > SIZE=3829: 553 5.7.1 [BL21] Connections will not be accepted from ###.72.###.129, because the ip is in Spamhaus's list; s
$headers = "From: Sender Name <info#senderweb.com >";
$headers = "Reply-To: info# senderweb.com \r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'MIME-Version: 1.0' . "\r\n";
I also look at Spamhaus's list by this ip, where I found my ip is listed in the XBL.
Please where is my problem here to display sender name at inbox?
Full Code:
$subject = "My subject";
$message .= "<html>";
$message .= "<head>";
$message .= "<style type=\"text/css\" media=\"screen\">";
$message .= "a:link, a:visited {color:#A0C804; text-decoration:none;}";
$message .= "a:hover {color:#339933; text-decoration:none;}";
$message .= "body {background-color:#FFFFFF;";
$message .= "font-family:Arial, Helvetica, sans-serif;";
$message .= "color:#000000;";
$message .= "font-size:12px;}";
$message .= "p.general {font-size: 14px;";
$message .= "line-height: 16px;";
$message .= "font-weight: normal;";
$message .= "padding-right:20px;";
$message .= "padding-left:17px;";
$message .= "margin-bottom:3px;}";
$message .= ".page {background-color:#ff0000;";
$message .= "padding:0px;";
$message .= "width:100%;}";
$message .= ".content {width:100%;";
$message .= "height:auto;";
$message .= "background-color:#FFFFFF;";
$message .= "padding:10px;";
$message .= "border:#ECEBEB;}";
$message .= "span.prospan {font-size: 14px;";
$message .= "line-height: 16px;";
$message .= "padding-left:20px;";
$message .= "margin-bottom:10px;}";
$message .= "p.proitem {font-size: 14px;";
$message .= "margin-bottom:10px;";
$message .= "padding-left:17px;}";
$message .= "p.tota {color: #ff0000;";
$message .= "padding-left:17px;";
$message .= "font-size: 14px;";
$message .= "margin-bottom:20px;";
$message .= "font-weight: bold;}";
$message .= "p.soong {color: #000000;";
$message .= "padding-left:17px;";
$message .= "margin-bottom:10px;";
$message .= "font-size: 14px;";
$message .= "font-weight: bold;}";
$message .= "p.foot {color: #000000;";
$message .= "margin-bottom:10px;";
$message .= "padding-left:17px;";
$message .= "font-size: 14px;}";
$message .= "</style>";
$message .= "<body>";
$message .= "<div class=\"page\">";
$message .= "<div class=\"content\">";
$message .= "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#ECEBEB\">";
$message .= "<tr>";
$message .= "<td style=\"text-align:left;\" bgcolor=\"#FF6699\"><img src=\"http://www.myweb.com.au/images/logo.png\" width=\"99\" height=\"83\" style=\"padding:15px;\" /></td>";
$message .= "<td style=\"text-align:right;\" bgcolor=\"#FF6699\"><h2 style=\"color:#ffffff;padding:20px;\" >Web name</h2></td>";
$message .= "</tr>";
$message .= "<tr>";
$message .= "<td><table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">";
$message .= "</tr>";
$message .= "<tr>";
$message .= "<td width=\"100%\" cellpadding=\"20\" align=\"left\"><br>";
$message .= "<p class=\"general\"><b>Congratulation ! </b></p><br>";
$message .= "<p class=\"general\">Dear <b>".$my_name."</b> ,</p><br>";
$message .= "<p class=\"general\">Massage to clint.</p><br>";
$message .= "</td>";
$message .= "</tr>";
$message .= "</table>";
$message .= "</div>";
$message .= "</div>";
$message .= "</body>";
$message .= "</html>";
$headers = "From: Sender Name <info#senderweb.com >";
$headers = "Reply-To: info#senderweb.com \r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'MIME-Version: 1.0' . "\r\n";
mail($email,$subject,$message,$headers);
Send a delist request for sender address. Any local cPanel user can use the 127.0.0.1 IP address to send mail without authentication. This can make it difficult for system administrators to determine which cPanel account sent the mail, especially when a malicious user spoofs an email address to disguise the origin of the email.
To require cPanel & WHM to put the actual sender in the header, enable the Experimental: Rewrite From: header to match actual sender option in WHM's Exim Configuration Manager interface (Home >> Exim Service Configuration >> Exim Configuration Manager). Check here https://documentation.cpanel.net/display/CKB/How+to+Prevent+Email+Abuse
I have the following issues.
I receive separate emails for each iteration of the loop. I want mail to be only sent once with all of the items iterated.
<?php
// Honey pot trap
// Create a hidden input that is only visible to bots. If it's empty than proceed.
if (empty($_POST['humancheck'])){
// Proceeed if submit button have been pressed
$fullName = $_POST['fname'];
$email = $_POST['email'];
$stage = $_POST['stage'];
include("db.php");
$resources = "select * from resources where stage LIKE '%".$stage."%'";
$run_query = mysqli_query($con, $resources);
while($row = mysqli_fetch_array($run_query)) {
$data[] = array(
'format' => $row['format'],
'title' => $row['title'],
'costs' => $row['cost'],
'stage' => $row['stage'],
'topic' => $row['topic'],
'link' => $row['link']
);
}
foreach($data as $item) {
// Sanitize input data
$clean_fullName = htmlspecialchars($fullName);
$clean_email = htmlspecialchars($email);
// Mail Set up
$to = $clean_email;
$to_us = "info#email.com";
// Email subject
$subject = "Your custom resource pack has arrived!";
$subject_us = "New custom resource delivered to: $clean_email";
$message = '<html><body>';
$message .= "<p>";
$message .= "Hi $clean_fullName, <br><br>";
$message .= " Based on your responses, we have created a custom resource pack tailored to your needs. <br><br>";
$message .= "<b>{$item['title']}</b><br>";
$message .= "{$item['format']} <br>";
$message .= "{$item['costs']} <br>";
$message .= "{$item['link']} <br><br>";
$message .= " If you have any questions, do not hesitate to reach out to us. <br><br>";
$message .= "</p>";
$message .= '</body></html>';
$message_us = "The below message was sent to $clean_fullName <br>
<i> Hi $clean_fullName <br>";
$message_us .= "\r\n Based on your responses, we have created a custom resource pack tailored to your needs: \r\n";
$message_us .= "\r\n If you have any questions, do not hesitate to reach out to us. \r\n";
// Headers
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <info#email.com>' . "\r\n";
}
mail($to,$subject,$message,$headers);
mail($to_us,$subject_us,$message_us,$headers);
}
?>
what happens is the while loops to the data that is stored in an array. That array is used in foreach. and outside of the loops, the mail is suppose to mail the result.
In theory this should of worked but its not working.
Try this. Edit last part of your code in this way. Take one time parameters of mail content outside the loop, and let loop make only the message content.
$clean_fullName = htmlspecialchars($fullName);
$clean_email = htmlspecialchars($email);
$to = $clean_email;
$to_us = "info#email.com";
$subject = "Your custom resource pack has arrived!";
$subject_us = "New custom resource delivered to: $clean_email";
$message = '<html><body>';
$message .= "<p>";
$message .= "Hi $clean_fullName, <br><br>";
$message .= " Based on your responses, we have created a custom resource pack tailored to your needs. <br><br>";
foreach($data as $item) {
$message .= "<b>{$item['title']}</b><br>";
$message .= "{$item['format']} <br>";
$message .= "{$item['costs']} <br>";
$message .= "{$item['link']} <br><br>";
}
$message .= " If you have any questions, do not hesitate to reach out to us. <br><br>";
$message .= "</p>";
$message .= '</body></html>';
$message_us = "The below message was sent to $clean_fullName <br><i> Hi $clean_fullName <br>";
$message_us .= "\r\n Based on your responses, we have created a custom resource pack tailored to your needs: \r\n";
$message_us .= "\r\n If you have any questions, do not hesitate to reach out to us. \r\n";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <info#email.com>' . "\r\n";
mail($to,$subject,$message,$headers);
mail($to_us,$subject_us,$message_us,$headers);
I'm sure I'm wrong about something basic, but can not find where the error is. I will appreciate your help.
I have a php page with a single 4 fields contact form.
I need send the name and email as variable, so i can see it properly when email is received.
IT WORKS - BUT DONT SEND NAME AND EMAIL AS VARIABLE:
All messages arrives as "no-reply#luchodomain.com" and doesnt look professional (and can't do reply from my outlook)
if ($_POST) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "lucho#hotmail.com";
$subject = "Website CONTACT";
$headers = "From: no-reply#luchodomain.com" . "\r\n" ;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$message .= "<tr><td><strong>Subject:</strong> </td><td>" . strip_tags($_POST['subject']) . "</td></tr>";
$message .= "<tr><td><strong>Message:</strong> </td><td>" . strip_tags($_POST['message']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
mail($to,$subject,$message,$headers);
}
IT DOENST WORKS (but have the format and variables as i need)
I would like receive the messages like is normal Name, so i can do a quick reply. -This code don't send email, doesn't work-
if ($_POST) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "lucho#hotmail.com";
$subject = "Website CONTACT";
$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$message .= "<tr><td><strong>Subject:</strong> </td><td>" . strip_tags($_POST['subject']) . "</td></tr>";
$message .= "<tr><td><strong>Message:</strong> </td><td>" . strip_tags($_POST['message']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
mail($to,$subject,$message,$headers);
}
I will appreciate your help with this "headers" issue!
Thank you.
Make sure that you are receiving data in your post array. Make sure your form action. You have declared $message variable to blank after assigning the post value in it before. That's not a good trick enough. Please check updated code and let me know.
if ($_POST) {
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$subject = strip_tags($_POST['subject']);
$message = strip_tags($_POST['message']);
$to = "lucho#hotmail.com";
$subject = "Website CONTACT";
$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//$message = "";
//$message .= '';
$message .= "\r\nName: " . $name . "";
$message .= "Email: " . $email . "\r\n";
$message .= "Subject: " . $subject . "\r\n";
$message .= "Message: " . $message . "";
//$message .= "";
//$message .= "";
mail($to,$subject,$message,$headers);
}
$to = 'pawanvikasitha2001#gmail.com, aravindasamapath87#gmail.com'; $subject = 'NEW ORDER HAS PLACED'; $message = "$name"; mail ($to,$subject,$message);
When you use the double quotes, You can simply add variables to it. Look at the $message
I am collecting information through a basic HTML form. Some of the fields are arrays indicated with [] after their name.
I have successfully written to a MySQL database and I am now trying to put the array values into a PHP-generated email. The email is being sent successfully with some of the variables printing, but none of the array values are coming through. How do I go about this?
$name, $position and $email are the values I am having issues with:
<?php
$to = "myemail#email.com";
$subject = "Media Request";
$message = "A media credential request has been submitted for $outlet. The editor is $editor and their contact info is $Eemail and $phone.";
$message .= '<html><body>';
$message .= "<h2>Credential Request</h2>";
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr><td align=right><strong>Name:</strong> </td>
<td>" . strip_tags("$name") . "</td>
<td align=right><strong>Position:</strong> </td>
<td>" . strip_tags("$position") . "</td>
<td align=right><strong>Email:</strong> </td>
<td>" . strip_tags("$email") . "</td></tr>";
$message .= "</table>";
$message .= ("Here are the comments and special instructions: $notes ");
$from = "email#email.com";
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to,$subject,$message,$headers);
?>
Assuming you have captured the form data in the variables you mentioned, you can use one of the following methods to output the array values:
Loop through the elements
foreach ($name as $name_field) {
$message .= "Your text here. $name_field. More Text";
}
Implode() and echo
You can convert the entire array into a string in one line using implode():
$message .= "Your text here." . implode(',', $name) . "More text here";
Note:
Verify that you have the expected data in $name, $position and $email. You can do this with var_dump():
var_dump($name, $position, $email);