Been struggling very much with only sending the fields that people fill in. It is a simple order form with text fields. But I want it so that only those fields that are field in get sent to my alert email. I tried the codes on the topic "PHP form: Success email with only filled fields" but my php script crashes when I do. Here is my code before I tried any modifying. This email fine only that it includes all fields I only want the one filled in. Please help I am a total noob in php. All help appreciated.
<?
$silver_name_badges = !empty($_POST['silver_name_badges']) ? ($_POST['silver_name_badges'])) : false;
$silver_name_badges = $_POST['silver_name_badges'];
$coffee_mug = $_POST['coffee_mug'];
$plastic_bag = $_POST['plastic_bag'];
$paper_bag = $_POST['paper_bag'];
$candy = $_POST['candy'];
$moist_towlette = $_POST['moist_towlette'];
$notepad_and_pen = $_POST['notepad_and_pen'];
$tuck_box = $_POST['tuck_box'];
$red_tie = $_POST['red_tie'];
$cap = $_POST['cap'];
$name = $_POST['Attention_To'];
$red_lanyard = $_POST['red_lanyard'];
$white_lanyard = $_POST['white_lanyard'];
$green_lanyard = $_POST['green_lanyard'];
$black_lanyard = $_POST['black_lanyard'];
$LC2415 = $_POST['LC2415'];
$FOM_2NTRI = $_POST['FOM_2NTRI'];
$ASTRO_165WMT = $_POST['ASTRO_165WMT'];
$FOL_AJ3015 = $_POST['FOL_AJ3015'];
$ACIES_NT = $_POST['ACIES_NT'];
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.ama-japan.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', 'ravila#ama.com');
// Set parameters of the email
$to = "joe#ama.com";
$subject = "Ama Promo Items Ordered";
$from = " jurt#ama.com";
$headers = "From: $from";
$message = "";
$message .= "Order has been placed. Attn to: $name .\n
Items:\n";
if($Phone)
$Body .= "Phone: "; $Body .= $Phone; $Body .= "\n";
$message .="
Silver Name Badges: $silver_name_badges\n
Coffee Mug: $coffee_mug\n
Plastic Literature Bag: $plastic_bag\n
Amada Bag: $paper_bag\n
Candy: $candy\n
Notepad & Pen: $notepad_and_pen\n
Tuck Box: $tuck_box\n
Amada Tie: $red_tie\n
Candy: $candy\n
Moist Towlette: $moist_towlette\n
Cap: $cap\n
Lanyard:
Red - $red_lanyard
White - $white_lanyard
Green - $green_lanyard
Black - $black_lanyard\n
Rock Glass:
LC2415 - $LC2415
FOM 2NTRI - $FOM_2NTRI
ASTRO 165WMT - $ASTRO_165WMT
FOL AJ3015 - $FOL_AJ3015
ACIES NT - $ACIES_NT";
// Mail function that sends the email.
mail($to,$subject,$message,$headers);
header('Location: thank-you.html');
?>
The errors might be related to unset POST variables.
How about a loop? It will only use what is sent over.
$message = "";
$message .= "Order has been placed. Attn to: $name .\n
Items:\n";
foreach ($_POST as $fieldName => $fieldValue){
if (!empty($fieldValue))
$message .= " ". str_replace('_',' ',$fieldName) .": $fieldValue\n";
}
OK I added this and worked great. How the email comes back with the field name with underscores. How to send without underscores?:
<?php
//$silver_name_badges = !empty($_POST['silver_name_badges']) ? ($_POST['silver_name_badges'])) : false;
$SilverNameBadges = $_POST['Silver Name Badges'];
$CoffeeMug = $_POST['coffee_mug'];
$PlasticLiteratureBag = $_POST['plastic_bag'];
$paper_bag = $_POST['paper_bag'];
$candy = $_POST['candy'];
$moist_towlette = $_POST['moist_towlette'];
$notepad_and_pen = $_POST['notepad_and_pen'];
$tuck_box = $_POST['tuck_box'];
$red_tie = $_POST['red_tie'];
$cap = $_POST['cap'];
$name = $_POST['Attention_To'];
$red_lanyard = $_POST['red_lanyard'];
$white_lanyard = $_POST['white_lanyard'];
$green_lanyard = $_POST['green_lanyard'];
$black_lanyard = $_POST['black_lanyard'];
$LC2415 = $_POST['LC2415'];
$FOM_2NTRI = $_POST['FOM_2NTRI'];
$ASTRO_165WMT = $_POST['ASTRO_165WMT'];
$FOL_AJ3015 = $_POST['FOL_AJ3015'];
$ACIES_NT = $_POST['ACIES_NT'];
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.amada-america.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', 'ravila#amada.com');
// Set parameters of the email
$to = "ravila#amada.com";
$subject = "Amada Promo Items Ordered";
$from = " nostrowski#amada.com";
$headers = "From: $from";
$message = "";
$message .= "Order has been placed. Attn to: $name .\n
Items:\n";
foreach ($_POST as $fieldName => $fieldValue){
if (!empty($fieldValue))
$message .= " $fieldName: $fieldValue\n";
}
// Mail function that sends the email.
mail($to,$subject,$message,$headers);
header('Location: thank-you.html');
?>
Related
I have the below code. I usually send an email to one recipient. My question is how can I modify for it to send to multiple recipients that are in my database.
Suppose I have a table called "tblemails" and a column called "email".
Note:
I also dont want to show all address to each member of my list (something like using Bcc).
Please Help?
<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "sender#gmail.com";
$to = "receiver#gmail.com";
$subject = "Online order";
$message = "You just ordered";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
?>
I am sure you can fetch the email data from the database,
You can update header string as
$headers .= 'BCC: '. implode(",", $emailData) . "\r\n";
$emailData - Should be 1-D array which should contains all email ids. ref
you can use while loop
$a = mysqli_query($con,"SELECT email FROM table");
while($row = mysqli_fetch_array($a)){$email = $row['email'];mail($email,$subject,$msg,$header);}}
I hope you know how to fetch the email ids from the database.
$link = mysqli_connect("localhost", "root", "password", "DBName");
$sql = "SELECT * FROM tableA";
if ($res = mysqli_query($link, $sql)) {
if (mysqli_num_rows($res) > 0) {
while ($row = mysqli_fetch_array($res)) {
$recipients[] = $row['email'];
}
}
}
$to = 'some#email.com';
$bcc = implode(',', $recipients);
$headers .= 'From: noreply#company.com\r\n'; //here you can set sent from
$headers .= 'BCC: '.$bcc. '\r\n';
mail($to,$subject,$message, $headers);
I know the title is weird I cant for the life of me phrase it well lol.
I have done searches with multiple ways of phrasing the question and nothing shows up for this.
I have the email scripting working on the website im building and its fantastic! but when i edited the mail code to add extra message lines its made the sequence go wrong.
here is the code im using for the email message area:
<?php
require_once "Mail.php";
// load the variables form address bar
$name = $_REQUEST["name"];
$subject = 'Customer Feedback';
$message = $_REQUEST["message"];
$from = $_REQUEST["from"];
$compname = $_REQUEST["companyName"];
$ph = $_REQUEST["phone"];
$acp = $_REQUEST['allowCommentPublish'];
$marketing = $_REQUEST['incmarketing'];
$verif_box = $_REQUEST["verif_box"];
// Checking the check boxes and marking as appropriate
if(isset($_POST['allowCommentPublish']))
{
$acp = 'Yes';
}
else
{
$acp = 'No';
}
if(isset($_POST['incmarketing']))
{
$marketing = 'Yes';
}
else
{
$marketing = 'No';
}
// Optional data checker
if($compname == '')
{
$compname = 'N/A';
}
if($ph == '')
{
$ph = 'N/A';
}
// remove the backslashes that normally appears when entering " or '
$name = stripslashes($name);
$message = stripslashes($message);
$subject = stripslashes($subject);
$acp = stripcslashes($acp);
$marketing = stripcslashes($marketing);
$from = stripslashes($from);
// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon'])
{
// if verification code was correct send the message and show this page
$ToEmail = "email#email.com";
$message = "Name: ".$name."\n".$message;
$message = "From: ".$from."\n".$message;
$message = "Comments: ".$message."\n".$message;
$message = "Allow feedback to be Published: ".$acp."\n".$message;
$message = "[ OPTIONAL DATA ]"."\n".$message;
$message = "Company Name: ".$compname."\n".$message;
$message = "Phone Number: ".$ph."\n".$message;
$message = "Allow extra Marketing? ".$marketing."\n".$message;
$headers = array ('From' => $from,
'To' => $ToEmail,
'Subject' => 'Feedback: '.$subject);
$smtp = Mail::factory('smtp', array ('host' => 'smtp.vic.exemail.com.au', 'auth' => false));
$mail = $smtp->send($ToEmail, $headers, $message);
// delete the cookie so it cannot sent again by refreshing this page
setcookie('tntcon','');
header("Location: /feedback_sent.php");
exit;
}
else
{
// if verification code was incorrect then return to contact page and show error
header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
exit;
}
?>
In my mind this should spit out the message body as this:
Name: name here
From: Email address
Comments: Message here
Allow feedback to be published: response
[ OPTIONAL DATA ]
Company Name: Company
Phone Number: Phone
Allow extra Marketing:
This should be how its seen in the email right?
What im actually getting is this:
Allow feedback to be Published: response
[ OPTIONAL DATA ]
Company Name: company
Phone Number: phone
Allow extra Marketing? Response
From: Email address
Name: name here
Comments: Message here
Is this normal? or have i inadvertently snuffed it somewhere along the lines and its messing with my head as payment?
Thanks for any help on this.
EDIT: Updated code.
<?php
// -----------------------------------------
// The Web Help .com
// -----------------------------------------
// remember to replace your#email.com with your own email address lower in this code.
require_once "Mail.php";
// load the variables form address bar
$name = $_REQUEST["name"];
$subject = 'Customer Feedback';
$comment = $_REQUEST["message"];
$from = $_REQUEST["from"];
$compname = $_REQUEST["companyName"];
$ph = $_REQUEST["phone"];
$acp = $_REQUEST['allowCommentPublish'];
$marketing = $_REQUEST['incmarketing'];
$verif_box = $_REQUEST["verif_box"];
// Checking the check boxes and marking as appropriate
if(isset($_POST['allowCommentPublish']))
{
$acp = 'Yes';
}
else
{
$acp = 'No';
}
if(isset($_POST['incmarketing']))
{
$marketing = 'Yes';
}
else
{
$marketing = 'No';
}
// Optional data checker
if($compname == '')
{
$compname = 'N/A';
}
if($ph == '')
{
$ph = 'N/A';
}
// remove the backslashes that normally appears when entering " or '
$name = stripslashes($name);
$comment = stripslashes($comment);
$subject = stripslashes($subject);
$acp = stripcslashes($acp);
$marketing = stripcslashes($marketing);
$from = stripslashes($from);
// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon'])
{
// if verification code was correct send the message and show this page
$ToEmail = "jim#digital2go.com.au";
$message = "Name: ".$name."\n".$message;
$message .= "From: ".$from."\n".$message;
$message .= "Comments: ".$comment."\n".$message;
$message .= "Allow feedback to be Published: ".$acp."\n".$message;
$message .= "[ OPTIONAL DATA ]"."\n".$message;
$message .= "Company Name: ".$compname."\n".$message;
$message .= "Phone Number: ".$ph."\n".$message;
$message .= "Allow extra Marketing? ".$marketing."\n".$message;
$headers = array ('From' => $from,
'To' => $ToEmail,
'Subject' => 'Feedback: '.$subject);
$smtp = Mail::factory('smtp', array ('host' => 'smtp.vic.exemail.com.au', 'auth' => false));
$mail = $smtp->send($ToEmail, $headers, $message);
// delete the cookie so it cannot sent again by refreshing this page
setcookie('tntcon','');
header("Location: /feedback_sent.php");
exit;
}
else
{
// if verification code was incorrect then return to contact page and show error
header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
exit;
}
?>
Make your message "continue" in the order you wish by doing this:
$message = "Name: ".$name."\n".$message;
$message .= "From: ".$from."\n".$message;
$message .= "Comments: ".$message."\n".$message;
$message .= "Allow feedback to be Published: ".$acp."\n".$message;
$message .= "[ OPTIONAL DATA ]"."\n".$message;
$message .= "Company Name: ".$compname."\n".$message;
$message .= "Phone Number: ".$ph."\n".$message;
$message .= "Allow extra Marketing? ".$marketing."\n".$message;
i'm working on a small project in which i need to send email about incorrect information in a listing. so, i need to send only the incorrect data from form. All works fine but not receiving mail. Is there anything i did wrong.Please help...
if(isset($_POST['report'])){
$name = $_POST['business'];
$address = $_POST['address'];
$phone =$_POST['phone'];
$email = $_POST['email'];
$website = $_POST['website'];
$toemail = "jafar.sain#gmail.com";
$fromwebsite = "www.biz15.co.in";
$error_listing = "business name";
$error_listing_link = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$subject = "Biz15 - Report an Error in a Listing from ".$fromwebsite;
$body = "You have been requested to go through the following errors from the listing - ".$error_listing."\n\n";
$body .= "Listing Details:\n";
$body .= "Listing Name - ".$error_listing."\n";
$body .= "Listing Url - ".$error_listing_link."\n\n";
$body .= "Error Details:\n";
if($name){$body .= "Business Name - ".$name."\n";}
if($address){$body .= "Address - ".$address."\n";}
if($phone){$body .= "Phone Number - ".$phone."\n";}
if($email){$body .= "Email - ".$email."\n";}
if($website){$body .= "Website - ".$website."\n\n";}
$body .= "---------------------------------------------------------------------------\n\n";
$headers = "MIME-Version: 1.0\n"."From: ".$toemail."\n"."Content-type: text/plain; charset=iso-8859-1\n";
if(#mail($toemail,$subject,$body,$headers)){
echo "<script type='text/javascript'>alert('Success');</script>";
}
else{
echo "<script type='text/javascript'>alert('Failed');</script>";
}
}
Currently I have 2 forms. On first user have to send code and receive it, and submit to second form and approve account. I need, when they put email and click submit, on email automatically is added code which they should get on their email, but they dont have to copy/paste code, because it should do automatically. Search for mysql_query("UPDATE users SET verify = 'verified', bullets = bullets + 5000 WHERE ID = '$ida'");
$showoutcome++; $outcome = "Your account is now verified!"; } - Here I need to add, $verifnum, because that's the code which they should get on their email, but as I said script should approve it automatically, and I will use only one form where they enter just email and click verify.
<?php
$saturate = "/[^a-z0-9]/i";
$saturated = "/[^0-9]/i";
$sessionidraw = $_COOKIE['PHPSESSID'];
$sessionid = preg_replace($saturate,"",$sessionidraw);
$userip = $_SERVER[REMOTE_ADDR];
$gangsterusername = $usernameone;
$playerrank = $myrank;
$playerarray =$statustesttwo;
$playerrank = $playerarray['rankid'];
$email = $playerarray['email'];
$verified = $playerarray['verify'];
$ref = $playerarray['ref'];
if($verified == 'verified'){die('<font color=silver face=verdana size=1>Your account is already verified!'); }
if($_POST['verify'] AND $_POST['email']){
$newemail = $_POST['email'];
if(!preg_match("/^[\ a-z0-9._-]+#[a-z0-9.-]+\.[a-z]{1,20}$/i", $_POST['email'])){ $showoutcome++; $outcome = "The email you entered is invalid!"; }else{
$verifnum = rand(1111,9999);
$to = "$newemail";
$subject = "SG - Email Verification";
$header = "From: State Gangsters - Email Verification <admins#stategangsters.com>\r\n" .
'Reply-To: State Gangsters <noreply#sgangsters.com>' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";
$body = "Your verification code is $verifnum!";
if (mail($to, $subject, $body, $header)){ $showoutcome++; $outcome = "An email has been sent, please check your inbox!";
mysql_query("UPDATE users SET verify = '$verifnum', email = '$newemail' WHERE ID = '$ida'");
}}}
if($_POST['code'] AND $_POST['verifyit']){
$newcode = $_POST['code'];
$getcodee = mysql_query("SELECT verify FROM users WHERE ID = '$ida'");
$doit = mysql_fetch_array($getcodee);
$getcode = $doit['verify'];
if($newcode == $getcode AND $getcode > 0){
mysql_query("UPDATE users SET verify = 'verified', bullets = bullets + 5000 WHERE ID = '$ida'");
$showoutcome++; $outcome = "Your account is now verified!"; }
else{ $showoutcome++; $outcome = "The verification code you entered is incorrect!";
}}
?>
if($_POST['code'] AND $_POST['verifyit']) {
Change that to use $_GET, and create a link in your e-mail that will post back to the page with the appropriate variables, e.g.
$body = "Your verification code is <a href='$PHP_SELF?code=$verifnum&verifyit=1'>$verifnum</a>!";
This aside, your code is really messy (three functionalities in one script), full of obsolete things (<font color=silver>?), weird constructions (using die for regular program flow?) and guaranteed loopholes (mysql_query with variables inserted directly in the SQL?!?!!!). It's not clear where your $ida comes from anyway, but I'm guessing (hoping) that's a consequence of copy/pasting code here for a minimal example.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have a script that I wrote that pretty much emails form data and sends it to a txt file. My question is how do I exclude some of the message from being sent to the text file? I don't want to send to the text file this line :
$message .= "A quote will be forwarded to
Joe Greeninger before order is placed.\n";
please help! How?
<?php
//$silver_name_badges = !empty($_POST['silver_name_badges']) ? ($_POST['silver_name_badges'])) : false;
$SilverNameBadges = $_POST['Silver_Name_Badges'];
$CoffeeMug = $_POST['Coffee_Mug'];
$Plastic_Literature_Bag = $_POST['Plastic_Literature_Bag'];
$Amada_Bag = $_POST['Amada_bag'];
$Candy = $_POST['Candy'];
$Moist_Towlette = $_POST['Moist_Towlette'];
$Notepad_and_Pen = $_POST['Notepad_and_Pen'];
$Tuck_Box = $_POST['Tuck_Box'];
$Amada_Tie = $_POST['Amada_Tie'];
$Cap = $_POST['Cap'];
$name = $_POST['Attention_To'];
$Red_Lanyard = $_POST['Red_Lanyard'];
$White_Lanyard = $_POST['White_Lanyard'];
$Green_Lanyard = $_POST['Green_Lanyard'];
$Black_Lanyard = $_POST['Black_Lanyard'];
$Glass_LC2415_NT = $_POST['Glass_LC2415_NT'];
$Glass_FOM2NTRI = $_POST['Glass_FOM2NTRI'];
$Glass_ASTRO_165WNT = $_POST['Glass_ASTRO_165WNT'];
$Glass_FOL_AJ3015 = $_POST['Glass_FOL_AJ3015'];
$Glass_ACIES_NT = $_POST['Glass_ACIES_NT'];
$Notes = $_POST['Notes'];
$Ship_Preference = $_POST['Ship_Preference'];
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.amada-america.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', 'jgreeninger#amada.com');
// Set parameters of the email
$to = "ravila#amada.com";
$subject = "Amada Promo Items Ordered";
$from = " jgreeninger#amada.com";
$headers = "CC: ravila#amada.com";
$message = "";
$message .= date("m-d-Y\n");
$message .= "Order has been placed.
Items:\n";
foreach ($_POST as $fieldName => $fieldValue){
if (!empty($fieldValue))
$message .= " $fieldName: $fieldValue\n";
}
$message .= "A quote will be forwarded to
Joe Greeninger before order is placed.\n";
$message = str_replace("_"," ",$message);
// Mail function that sends the email.
mail($to,$subject,$message,$footer,$headers);
$fp = fopen("latc.txt", "a");
fwrite($fp, $message."\r\n");
fclose($fp);
header('Location: index.html');
?>
Change the order of things so you write the file before adding that line to the message:
foreach ($_POST as $fieldName => $fieldValue){
if (!empty($fieldValue))
$message .= " $fieldName: $fieldValue\n";
}
$message = str_replace("_"," ",$message);
$fp = fopen("latc.txt", "a");
fwrite($fp, $message."\r\n");
fclose($fp);
$message .= "A quote will be forwarded to
Joe Greeninger before order is placed.\n";
// Mail function that sends the email.
mail($to,$subject,$message,$footer,$headers);
Try this:
<?php
//$silver_name_badges = !empty($_POST['silver_name_badges']) ? ($_POST['silver_name_badges'])) : false;
$SilverNameBadges = $_POST['Silver_Name_Badges'];
$CoffeeMug = $_POST['Coffee_Mug'];
$Plastic_Literature_Bag = $_POST['Plastic_Literature_Bag'];
$Amada_Bag = $_POST['Amada_bag'];
$Candy = $_POST['Candy'];
$Moist_Towlette = $_POST['Moist_Towlette'];
$Notepad_and_Pen = $_POST['Notepad_and_Pen'];
$Tuck_Box = $_POST['Tuck_Box'];
$Amada_Tie = $_POST['Amada_Tie'];
$Cap = $_POST['Cap'];
$name = $_POST['Attention_To'];
$Red_Lanyard = $_POST['Red_Lanyard'];
$White_Lanyard = $_POST['White_Lanyard'];
$Green_Lanyard = $_POST['Green_Lanyard'];
$Black_Lanyard = $_POST['Black_Lanyard'];
$Glass_LC2415_NT = $_POST['Glass_LC2415_NT'];
$Glass_FOM2NTRI = $_POST['Glass_FOM2NTRI'];
$Glass_ASTRO_165WNT = $_POST['Glass_ASTRO_165WNT'];
$Glass_FOL_AJ3015 = $_POST['Glass_FOL_AJ3015'];
$Glass_ACIES_NT = $_POST['Glass_ACIES_NT'];
$Notes = $_POST['Notes'];
$Ship_Preference = $_POST['Ship_Preference'];
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.amada-america.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', 'jgreeninger#amada.com');
// Set parameters of the email
$to = "ravila#amada.com";
$subject = "Amada Promo Items Ordered";
$from = " jgreeninger#amada.com";
$headers = "CC: ravila#amada.com";
$message = "";
$message .= date("m-d-Y\n");
$message .= "Order has been placed.
Items:\n";
foreach ($_POST as $fieldName => $fieldValue){
if (!empty($fieldValue))
$message .= " $fieldName: $fieldValue\n";
}
$message = str_replace("_"," ",$message);
// Mail function that sends the email.
$mailMsg = $message . " A quote will be forwarded to Joe Greeninger before order is placed.\n";
mail($to,$subject,$mailMsg,$footer,$headers);
$fp = fopen("latc.txt", "a");
fwrite($fp, $message."\r\n");
fclose($fp);
header('Location: index.html');
?>