I had asked a question yesterday about sending an email every three days which was answered so I'm not sure if I should create a new one or add to the old.
The check is working fine as I get the correct ouptut on screen, but when I try to send the email it is only sending one result. I've tried foreach loops, putting the mail function in different places none of which seem to work. My code is below, I've removed most of the message parts as they are just long tables.
**UPDATE ****
I've added the recipients array into the while loop and also set $subject and $headers to empty values before adding values. This has worked.
$sql = "SELECT * FROM bookings " .
"WHERE DATE(date) > DATE(NOW()) " .
"AND dateofquote != '' " .
"AND email != '' " .
"AND confirmed = 0";
$result = mysql_query($sql);
$num_rows = mysql_numrows($result);
$today = date('Y-m-d');
if ($num_rows) {
while ($row = mysql_fetch_array($result)) {
$recipients = array(); // Updated
$id = $row['id'];
// rest of rows from db
$date_time1 = new DateTime($today);
$date_time2 = new DateTime($date_of_quote);
$interval = $date_time1->diff($date_time2);
$diff = $interval->format('%a');
if ($diff % 3 == 0) {
if ($type == 'W') {
$message = '<table width="95%" border="0" cellspacing="0" align="center" style="border:1px solid #999;">';
// rest of table
echo '<h1>Weddding Email</h1>'.$message.'<br />End Wedding<br /><br /><hr>';
// tried to send email from here for this option
}
elseif ($type == 'D') {
$message = '<table width="95%" border="0" cellspacing="0" align="center" style="border:1px solid #999;">';
// rest of table
echo '<h1>Debs Email</h1>'.$message.'<br />End Debs<br /><br /><hr>';
// tried to send email from here for this option
}
elseif ($type == 'CR') {
$message = '<table width="95%" border="0" cellspacing="0" align="center" style="border:1px solid #999;">';
// rest of table
echo '<h1>Country Run Email</h1>'.$message.'<br />End Country Run<br /><br /><hr>';
// tried to send email from here for this option
}
elseif ($type == 'H') {
$message = '<table width="95%" border="0" cellspacing="0" align="center" style="border:1px solid #999;">';
// rest of table
echo '<h1>Hourly Email</h1>'.$message.'<br />End Hourly<br /><br /><hr>';
// tried to send email from here for this option
}
} else {
echo 'something went wrong';
}
$recipients[] = $email;
$subject = ''; // Updated
$headers = ''; // Updated
$subject .= "An $type_value Enquiry has been received from company.ie";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Name <email#email.com>' . "\r\n";
foreach($recipients as $to){
if(mail($to, $subject, $message, $headers)) {
echo "E-Mail Sent to ";
echo $to.'<br />';
} else {
echo "There was a problem";
}
}
}
}
Try like this inside your while loop. Your mail content is inside the while loop, but you are trying mail function outside the while loop, so it is sending last content to all your mails in $recipients array.
$subject='';
$headers='';
$subject .= "An $type_value Enquiry has been received from company.ie";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Absolute Limos <email#email.com>' . "\r\n";
mail($email, $subject, $message, $headers);
your problem lies here:
$recipients[] = $email;
You create your email array outside your loop, thus you only get the last email address value.
Put it in your
while ($row = mysql_fetch_array($result)) {
Related
Im trying to send an email to 2 variables currently I have tried to add 3 emails to an array and put that into a variable and get the other email from the form, I then dont know how to put both of those variables together when sending so they each have their own "to" but this does not work or something doesnt and I dont know what?? And yes I have real emails that I use these are placeholders for this!!!
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['submit'])) {
$email = $_POST['LOGSE'];
$email2 = array("test#test.com", "test#test.com", "test#test.com");
$name = $_POST['full_name'];
$eventtitle = $_POST['EventT'];
$InCharge = $_POST['InCharge'];
$Venue = $_POST['Venue'];
$VenY = $_POST['VenR'];
if($VenY != "Yes"){
$ava = " Have not checked if";
}
else{
$ava = "";
}
$dates = $_POST['dateS'];
$datee = $_POST['dateE'];
$adults = $_POST['Adults'];
$children = $_POST['Children'];
$catreq = $_POST['CateReq'];
if (catreq != ''){
$catreq = $catreq;
}
else{
$catreq = "No Catering Needed";
}
$logreq = $_POST['LogReq'];
if (logreq != ''){
$logreq = $logreq;
}
else{
$logreq = "No Logistic Equipment Needed";
}
$itreq = $_POST['ITReq'];
if (itreq != ''){
$itreq = $itreq;
}
else{
$itreq = "No IT Needed";
}
$tran = $_POST['TransR'];
if($tran != Yes){
$tran = "NO ";
}
else{
$tran = "";
}
$Risk = $_POST['RiskR'];
if($Risk != Yes){
$Risk = "NO ";
}
else{
$Risk = "";
}
$othern = $_POST['OtherN'];
// The Email:
$from = 'test#test.com';
$to = $email;
$to = $email2;
$subject = 'Event Form ' .$eventtitle;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type:text/html;charset=UTF-8' . "\r\n";
$headers .= 'From: Event Form<test#test.com>' . "\r\n";
$headers .= 'Cc: test#test.com, test#test.com' . "\r\n";
$body = '<html>
<head>
<title>Event</title>
<style>
h1 {
font-family: "Century Gothic", CenturyGothic,
AppleGothic, sans-serif;
}
h3 {
font-family: "Century Gothic", CenturyGothic,
AppleGothic, sans-serif;
}
</style>
</head>
<body>
<h1>Event Details</h1>
<h3>Name: '.$name.'</h3>
<h3>Event Title: '.$eventtitle.'</h3>
<h3>Event Manager: '.$InCharge.'</h3>
<h3>Venue: '.$Venue.' - '.$ava.' Available</h3>
<h3>Date Start: '.$dates.'</h3>
<h3>Date End: '.$datee.'</h3>
<h3>Adults Attending: '.$adults.' Children Attending:
'.$children.'</h3>
<h3>Catering Requirements: '.$catreq.'</h3>
<h3>Logistic Requirements/Equipment: '.$logreq.'</h3>
<h3>IT Requirements: '.$itreq.'</h3>
<h3>Other Notes: '.$othern.'</h3>
<h3><font color="red">'.$tran.'</font>Transport Has Been
Booked</h3>
</body>
</html>' . "\r\n";
mail( $to, $subject, $body ,$headers );
/* echo "An Email Has Been Sent<br>Thank You."; */
header('Location: ./thanks.html');
}
}
The $to in mail function should be a string. If there are more than one email address then those should be comma separated. In your case you might need to do like following.
$to = $email . ','. implode(',', $email2);
Add email address with the comma
$email_to = "test#test.com,some#other.com,yet#another.net";
Also you can add
$headers = "Bcc: someone#domain.com";
Use a foreach on the array:
foreach($email2 as $to){
mail( $to, $subject, $body ,$headers );
}
Or like others are suggesting:
$to = $email.",".implode(",",$email2);
That doesn't make sense:
$to = $email;
$to = $email2;
Parmaeter $to should be a string of comma-seperated email-addresses, e.g.:
$to = $email1 . ", " . $email2 . ", " . $email3;
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 7 years ago.
I have a form I got working fine but when I try and redirect after a form submission to a thank you page but get and error of " Cannot modify header information - headers already sent by ". I understand the headers are being modified in the mail() part but how do you do this without an error?
Code:
<?php
//if "email" variable is filled out, send email
if ( isset($_REQUEST['email']) ) {
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you
submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['phone'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
//Form Variables
//Personal Information
$subject = "Smile Guide";
$email = $_REQUEST['email'];
$first_name = $_REQUEST['first_name'];
$last_name = $_REQUEST['last_name'];
$phone = $_REQUEST['phone'];
$admin_email = "packy#ocularlogic.com,$email";
//Stage 1
$chipped = $_REQUEST['smile-fault-1'];
$color = $_REQUEST['smile-fault-2'];
$gaps = $_REQUEST['smile-fault-3'];
$worn = $_REQUEST['smile-fault-4'];
$crooked = $_REQUEST['smile-fault-5'];
$metal = $_REQUEST['smile-fault-6'];
//Stage 2
$aggressive = $_REQUEST['smile-prefered-1'];
$mature = $_REQUEST['smile-prefered-2'];
$vigorous = $_REQUEST['smile-prefered-3'];
$dominant = $_REQUEST['smile-prefered-4'];
$focused = $_REQUEST['smile-prefered-5'];
$enhanced = $_REQUEST['smile-prefered-6'];
$soften = $_REQUEST['smile-prefered-7'];
$hollywood = $_REQUEST['smile-prefered-8'];
$functional = $_REQUEST['smile-prefered-9'];
$natural = $_REQUEST['smile-prefered-10'];
$youthful = $_REQUEST['smile-prefered-11'];
$oval = $_REQUEST['smile-prefered-12'];
//Stage 3
$shade = $_REQUEST['smile-color'];
//List errors
$error_message = "";
$string_exp = "/^[A-Za-z0-9 .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$phone)) {
$error_message .= 'The Phone Number you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
//The Message
$content = '<html><body><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="center">';
$content .= '<img src="http://smiletothemaxdentallab.com/guide/smile-logo.jpg" style="display: block; margin: 10px auto;">';
$content .= '<h1 style="color: #c51f4f;">Smile Guide</h1>';
$content .= "<h2 style='background-color:#c51f4f; color:#fff; padding:10px 0;'>Client Information</h2><ul style='list-style-type: none; color:#999999;'>";
$content .= "<li>Name:".$last_name.",".$first_name."</li>";
$content .= "<li>Phone:".$phone."</li>";
$content .= "<li>Email:".$email."</li>";
$content .= "</ul>";
$content .= "<h2 style='background-color:#c51f4f; color:#fff; padding:10px 0;'>Current Teeth Issues</h2><ul style='list-style-type: none; color:#999999;'>";
$content .= isset($_POST['smile-fault-1']) ? "<li>".$chipped."</li>" : "";
$content .= isset($_POST['smile-fault-2']) ? "<li>".$color."</li>" : "";
$content .= isset($_POST['smile-fault-3']) ? "<li>".$gaps."</li>" : "";
$content .= isset($_POST['smile-fault-4']) ? "<li>".$worn."</li>" : "";
$content .= isset($_POST['smile-fault-5']) ? "<li>".$crooked."</li>" : "";
$content .= isset($_POST['smile-fault-6']) ? "<li>".$metal."</li>" : "";
$content .= "</ul>";
$content .= "<h2 style='background-color:#c51f4f; color:#fff; padding:10px 0;'>Desired Color</h2><ul style='list-style-type: none; color:#999999;'>";
$content .= "<li>".$shade."</li>";
$content .= "</ul>";
$content .= "</td></tr><tr><td style='background-color:#F7F7F7; color:#999999; text-align:center; padding: 50px 0;'><p>Brought to you be AOC Dental Lab</p><p>Toll free (800) 729-1593</p><p>1724 E Sherman Ave | Coeur d’Alene, Idaho | 83814</p>";
$content .= "</td></tr></table></body></html>";
//Set up Header
$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";
//Send Email
$send = mail($admin_email, $subject, $content, $headers);
if($send) {
header("Location: http://website.com/smile-guide/thank-you");
}
}
?>
This error is being caused by the fact that you have already sent data to the client at the moment you are trying to send the headers (which should be sent first).
Check your page encoding. Probably it is UTF-8+ (with UTF-8 signature)
If not then you need to check white spaces.
Don't forget to exit after redirect
if($send) {
header("Location: http://website.com/smile-guide/thank-you");
exit();
}
I have this link and then processed by this script:
<html>
<head>
</head>
<?php
/*//Disable error reporting
error_reporting(0);
*/
//Report runtime errors
//error_reporting(E_ERROR | E_WARNING | E_PARSE);
//<script>location.replace("http://www.mntr.xxx.com/update.php");</script>
//Report all errors
error_reporting(E_ALL);
//end of error reporting
if(isset($_POST['submit']) && $_POST['submit'] == 'Send') {
//var_dump($_POST['users']);
$size= sizeof($_POST['users']);
$i = 0;
$message = NULL;
// $message = null;
for($i=0; $i<$size; $i++){
$userId = $_REQUEST['users'][$i];
$message .= mailContent($userId);
}
$to = $_POST['email'];
$subject = 'This is a test';
$headers = 'From: xxx#live.com.ph' . "\r\n" .
'Reply-To: xxx#live.com.ph' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1\r\n';
mail($to, $subject, $message, $headers);
}
function mailContent($userId) {
$con=mysqli_connect("localhost","xxx","xxx","xxx");
$stmt = "SELECT * from CV where idvisa = '$userId'";
$result = mysqli_query($con, $stmt);
$row=mysqli_fetch_array($result);
$fName = $row['fName'];
$lName = $row['lName'];
$visaNumber = $row['visanumber'];
$idNumber = $row['idnumber'];
$statusApp = $row['statusapp'];
$accntVisaPhotoPath = $row['accntVisaPhotoPath'];
$passportPath = $row['passportPath'];
$message = "Your Username: YOUR EMAIL (small caps) PASSWD: 1234
<table>
<tr>
<td>Name</td><td>$fName $lName</td>
</tr>
<tr>
<td>CVs</td><td>Click Here</td>
</tr>
<tr>
<td>Visa Number</td><td>$visaNumber</td>
</tr>
<tr>
<td>ID Number</td><td>$idNumber</td>
</tr>
<tr>
<td>Application Status</td><td>$statusApp</td>
</tr>
<tr>
<td>Visa Copy</td><td><a href='http://mntr.xxx.com/".$accntVisaPhotoPath."'>Click to Download</a></td>
</tr>
<tr>
<td>Passport Copy</td><td><a href='http://mntr.xxx.com/".$passportPath."'>Click to Download</a></td>
</tr>
</table>";
// OTHER LOGICS GO HERE
return $message;
}
//Additional var
//Time
date_default_timezone_set('Asia/Manila');
//End Time
$email = $_POST['email'];
$subdate = date("Y-m-d");
$subdate2 = date("Y-m-d");
if (empty($subdate)) {
$sql="UPDATE CV SET subdateEmail='$email',subdate='$subdate WHERE idvisa='$userId'";
} else {
$sql="UPDATE CV SET subdateEmail2='$email',subdate2='$subdate2' WHERE idvisa='$userId'";
}
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "<center>You have sent CV(s) </b><br/><br/><br/><br/>YOU MAY NOW CLOSE THIS WINDOW</center>";
?>
It is working but I want to update 4 columns out of the selected users (in this case, idvisa) AFTER email. Right now, it doesn't update. I am thinking on the array that has been SELECTED.
Any idea?
Use this
error_reporting(E_ALL);
$con=mysqli_connect("localhost","xxx","xxx","xxx");
if(#mail($to, $subject, $message, $headers))
{
ate_default_timezone_set('Asia/Manila');
//End Time
$email = $_POST['email'];
$subdate = date("Y-m-d");
$subdate2 = date("Y-m-d");
if (empty($subdate)) {
$sql="UPDATE CV SET subdateEmail='$email',subdate='$subdate WHERE idvisa='$userId'";
} else {
$sql="UPDATE CV SET subdateEmail2='$email',subdate2='$subdate2' WHERE idvisa='$userId'";
}
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "<center>You have sent CV(s) </b><br/><br/><br/><br/>YOU MAY NOW CLOSE THIS WINDOW</center>";
}else{
echo "Mail Not Sent";
}
I am submitting a form which inserts record into database and then sends email to the specified address. The below code doesn't working for me. i'm getting errors.
if (isset($_POST['submit'])) {
//if (
// !empty($_POST['item_cid']) &&
// !empty($_POST['item_code']) &&
// !empty($_POST['item_name']) &&
// !empty($_POST['item_price']) &&
// !empty($_POST['item_qty']) &&
// is_array($_POST['item_cid']) &&
// is_array($_POST['item_code']) &&
// is_array($_POST['item_name']) &&
// is_array($_POST['item_price']) &&
// is_array($_POST['item_qty']) &&
// count($_POST['item_cid']) === count($_POST['item_code'])
// )
//{
foreach($_POST['item_cid'] as $key => $value) {
//Data for Orders Table
$cid = mysqli_real_escape_string($connection,$value);
$pcode = mysqli_real_escape_string($connection,$_POST['item_code'][$key]);
$pname = mysqli_real_escape_string($connection,$_POST['item_name'][$key]);
$pprice = mysqli_real_escape_string($connection,$_POST['item_price'][$key]);
$pqty = mysqli_real_escape_string($connection,$_POST['item_qty'][$key]);
//Data for Customers Table
$cname = mysqli_real_escape_string($connection,$_POST['item_cname'][$key]);
$cemail = mysqli_real_escape_string($connection,$_POST['item_cemail'][$key]);
$cphone = mysqli_real_escape_string($connection,$_POST['item_cphone'][$key]);
$caddress = mysqli_real_escape_string($connection,$_POST['item_caddress'][$key]);
$ctotal = mysqli_real_escape_string($connection,$_POST['item_ctotal'][$key]);
// $sql = "INSERT INTO orders (cid, ordprod_code, ordprod_name, ordprod_price, ordprod_qty) VALUES ('$value', '$pcode', '$pname', '$pprice', '$pqty')";
// $sql2 = "INSERT INTO customers (cid, cname, cemail, cphone, caddress, ctotal) VALUES ('$value','$cname','$cemail','$cphone','$caddress','$ctotal')";
if ($connection->query($sql) === TRUE) {
echo "Orders record created successfully \n";
}
// } else {
// echo "Error: " . $sql . "<br>" . $connection->error;
// }
if ($connection->query($sql2) === TRUE) {
echo "Customers record created successfully \n";
}
// } else {
// echo "Error: " . $sql2 . "<br>" . $connection->error;
} // close the loop
//********************************
// START EMAIL FUNCTION
//********************************
// PREPARE THE BODY OF THE MESSAGE
$message = '<html><body>';
$message .= '<img src="http://example.com/static/images/emailhead.jpg" alt="OMREL JEWELRY" />';
$message .= '<h3>Customer Information:</h3>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= '<tr><td><strong>Name:</strong></td><td>'. strip_tags($_POST['item_cname']) .'</td></tr>';
$message .= '<tr><td><strong>Email:</strong></td><td>'. strip_tags($_POST['item_cemail']) .'</td></tr>';
$message .= '<tr><td><strong>Phone:</strong></td><td>'. strip_tags($_POST['item_cphone']) .'</td></tr>';
$message .= '<tr><td><strong>Address:</strong> </td><td>'. strip_tags($_POST['item_caddress']) .'</td></tr>';
$message .= '</table>';
$message .= '</body></html>';
// MAKE SURE THE "FROM" EMAIL ADDRESS DOESN'T HAVE ANY NASTY STUFF IN IT
$pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i";
if (preg_match($pattern, $_POST['item_cemail'])) {
$cleanedFrom = $_POST['item_cemail'];
} else {
return "The email address you entered was invalid. Please try again!";
}
// CHANGE THE BELOW VARIABLES TO YOUR NEEDS
$to = 'info#domain.com';
$subject = 'New order Arrived CustomerID #'.$cid.' ';
$headers = "From: " . $cleanedFrom . "\r\n";
$headers .= "Reply-To: ".strip_tags($_POST['item_ceamil']) ."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if (mail($to, $subject, $message, $headers)) {
echo 'Your order has been sent. Our sales department will contact you soon...';
} else {
echo 'There was a problem sending the email.';
}
print_r($_POST['item_cname']);
} // Data Inserted & Emailed Close IF Statement
session_destroy();
The HTML
<p class="form-row">
<label class="" for="item_cname[]">Your Name <span class="required">*</span></lable>
<input class="input-text" type="text" name="item_cname[]" placeholder="Your Name" />
</p>
<p class="form-row">
<label class="" for="item_cemail[]">Email Address <span class="required">*</span></lable>
<input type="text" name="item_cemail[]" placeholder="Your Email Address"/>
</p>
<p class="form-row">
<label class="" for="item_cphone[]">Phone Number <span class="required">*</span></lable>
<input type="text" name="item_cphone[]" placeholder="Your Phone Number"/>
</p>
<p class="form-row">
<label class="" for="item_caddress[]">Address <span class="required">*</span></lable>
<textarea name="item_caddress[]" placeholder="Your Address" class="input-text" rows="2" cols="2" maxlength="140"></textarea>
</p>
The Errors
Notice: Undefined variable: sql in /home/public_html/dev/process.php
on line 48
Warning: mysqli::query(): Empty query in
/home/public_html/dev/process.php on line 48
Notice: Undefined variable: sql2 in /home/public_html/dev/process.php
on line 55
Warning: mysqli::query(): Empty query in
/home/public_html/dev/process.php on line 55
Warning: strip_tags() expects parameter 1 to be string, array given in
/home/public_html/dev/process.php on line 72
Warning: strip_tags() expects parameter 1 to be string, array given in
/home/public_html/dev/process.php on line 73
Warning: strip_tags() expects parameter 1 to be string, array given in
/home/public_html/dev/process.php on line 74
Warning: strip_tags() expects parameter 1 to be string, array given in
/home/public_html/dev/process.php on line 75
Warning: preg_match() expects parameter 2 to be string, array given in
/home/public_html/dev/process.php on line 81
All those errors pointing towards the strip_tags($_POST['item_*']) (the * represents the name of item).
How to fix this?
Are you looking for this. If yes, this should work for you:
<?php
if (isset($_POST['submit'])) {
foreach($_POST['item_cid'] as $key => $value) {
//Data for Orders Table
$cid = mysqli_real_escape_string($connection,$value);
$pcode = mysqli_real_escape_string($connection,$_POST['item_code'][$key]);
$pname = mysqli_real_escape_string($connection,$_POST['item_name'][$key]);
$pprice = mysqli_real_escape_string($connection,$_POST['item_price'][$key]);
$pqty = mysqli_real_escape_string($connection,$_POST['item_qty'][$key]);
//Data for Customers Table
$cname = mysqli_real_escape_string($connection,$_POST['item_cname'][$key]);
$cemail = mysqli_real_escape_string($connection,$_POST['item_cemail'][$key]);
$cphone = mysqli_real_escape_string($connection,$_POST['item_cphone'][$key]);
$caddress = mysqli_real_escape_string($connection,$_POST['item_caddress'][$key]);
$ctotal = mysqli_real_escape_string($connection,$_POST['item_ctotal'][$key]);
if ($connection->query($sql) === TRUE) {
echo "Orders record created successfully \n";
}
if ($connection->query($sql2) === TRUE) {
echo "Customers record created successfully \n";
}
}
$message = '<html><body>';
$message .= '<img src="http://example.com/static/images/emailhead.jpg" alt="OMREL JEWELRY" />';
$message .= '<h3>Customer Information:</h3>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= '<tr><td><strong>Name:</strong></td><td>'. $cname .'</td></tr>';
$message .= '<tr><td><strong>Email:</strong></td><td>'. $cemail .'</td></tr>';
$message .= '<tr><td><strong>Phone:</strong></td><td>'. $cphone .'</td></tr>';
$message .= '<tr><td><strong>Address:</strong></td><td>'. $ctotal .'</td></tr>';
$message .= '</table>';
$message .= '</body></html>';
$pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i";
if (preg_match($pattern, $cemail)) {
$cleanedFrom = $cemail;
} else {
return "The email address you entered was invalid. Please try again!";
}
$to = 'info#example.com';
$subject = 'New order Arrived CustomerID #'.$cid.' ';
$headers = "From: " . $cleanedFrom . "\r\n";
$headers .= "Reply-To: ".strip_tags($_POST['item_ceamil']) ."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if (mail($to, $subject, $message, $headers)) {
echo 'Your order has been sent. Our sales department will contact you soon...';
} else {
echo 'There was a problem sending the email.';
}
print_r($_POST['item_cname']);
} // Data Inserted & Emailed Close IF Statement
session_destroy();
?>
Probably one of your post data is array object.
Try to make print_r($_POST[xxx]) to check your POST values.
Strip Tags function parameter should not be an array object.
I have a table named 'an_posts' and a column inside the table named 'post_title'. I need to send an email to user when i select more than 'post_title'. But the code below is only send one 'post_title'. Why is that happened and what I have to add in the code so that the email send will retrieve two or more data from database ?
if($_GET["action"] == 'sendpostnewsletter')
{
global $post;
$post_id = $_POST["post_id"];
$emailtosender = $_POST["emailtosender"];
$subjecttitle = $_POST["subjecttitle"];
$sql = "select * from an_posts where post_type = 'post' and post_status = 'publish' and ID in ($post_id)";
$formssql = mysql_query($sql);
while ( $row = mysql_fetch_array($formssql) )
{
$message = '
<div align="center"><h3>'.$row['post_title'].'</h3></div>
<br />
<div style="text-align:justify; font-size:16px; font-family:Verdana, Geneva, sans-serif; font-weight:bold">
'.$row['post_content'].'
</div>';
}
$message .= "<hr />";
$headers = "From: Newsletter <list#domainname.com>" . "\n" ;
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\n";
wp_mail( $emailtosender , $subjecttitle , $message, $headers );
$result='<div id="message" class="updated fade"><p><strong><h5>done</h5></strong></p></div>';
echo $result;
}
You are overwriting the content of message each loop. Instead append to it:
//initialize outside the loop
$message='';
while ( $row = mysql_fetch_array($formssql) )
{
//then append - notice the dot .=
$message .= '
...