I cant seem to find a solution to this on the site. What I would like to do is to have the user click on a button. This will then send a mail to me or someone in the office and the mail would then contain the logged in user details. I am sending the mail successfully, but I am unsure on how to get the code to send me the users info. Here is my code:
include 'contact/config.php';
require_once 'class.user.php';
$user_home = new USER();
if(!$user_home->is_logged_in())
{
$user_home->redirect('index.php');
}
$stmt = $user_home->runQuery("SELECT * FROM tbl_client_info WHERE UCODE=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post)
{
$name = $row['firstname'];
$email = $row['billingemail'];
$subject = "myDraadloze Package Contact Card";
$message = stripslashes($_POST['Please contact user regarding example']);
$error = '';
if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail)
{
echo 'OK';
}
}
}
?>
Any help would really be appreciated.
Thanks
include 'contact/config.php';
require_once 'class.user.php';
$user_home = new USER();
if(!$user_home->is_logged_in())
{
$user_home->redirect('index.php');
}
else
{
$stmt = $user_home->runQuery("SELECT * FROM tbl_client_info WHERE UCODE=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post)
{
$name = $row['firstname'];
$email = $row['billingemail'];
$subject = "myDraadloze Package Contact Card";
$email_to = " email#gmail.com";
$message = .= "Firstname: ".($name)."\n\n";
$message = .= "Email: ".($email)."\n\n";
$message = .= "Firstname: ".($name)."\n\n";
$error = '';
if(!$error)
{
$headers = 'From: your Website/email'."\r\n".
'Reply-To: Email.#ste.com'."\r\n" .
'X-Mailer: PHP/' . phpversion();
if(#mail($email_to, $subject, $message, $headers))
{
echo 'OK';
}
}}
?>
Hope this helps!
the reply-to and from format doesnt look right. I would just create a variable for them and then stick it in the code.
$name = $row['firstname'];
$email = $row['billingemail'];
$subject = "myDraadloze Package Contact Card";
$message = stripslashes($_POST['Please contact user regarding example']);
$error = '';
$replyemail="'Reply-To: ".$name."<".$email.">'"."\r\n"; //looks likes this 'Reply-to: customer name <customeremail#whatever.com'\r\n
$fromemail="'from: ".$name."<".$email.">'"."\r\n"; //looks likes this 'from: customer name <customeremail#whatever.com'\r\n
//yours looked like this
//from:customername <customeremail#whatever.com\r\n
//these are headers and need to be seperated with '
//the ' should be at start and before \r\n
if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, $subject, $message,$fromemail.$replyemail
."X-Mailer: PHP/" . phpversion());
Related
Kindly seeking your help with the below code:
if( !$error ) {
move_uploaded_file($file_loc,$folder.$file);
$cuser = $userRow['userName'];
$res = mysql_query("SELECT * FROM users WHERE userId=".$_SESSION['user']);
$userRow = mysql_fetch_array($res);
$query = "INSERT INTO postoffers(postedby,reqName,reqEmail,reqHotel,reqOutlet,reqCnum,reqPostType,reqPostHead,reqPostDet,offerStarts,offerEnds,file,type,size) VALUES('$cuser','$rname','$remail','$rhotel','$routlet','$rcnum','$rposttype','$rposthead','$rpostdet','$rbdate','$redate','$file','$file_type','$file_size')";
$res = mysql_query($query);
if ($res) {
$errTyp = "success";
$errMSG = "Successfully Posted!";
unset($rname);
unset($remail);
unset($rhotel);
unset($routlet);
unset($rcnum);
unset($rposttype);
unset($rposthead);
unset($rpostdet);
unset($rbdate);
unset($redate);
unset($file);
$to = ;
$subject = "Your Post Offer";
$message = "Thank you " . $cuser . " for the Post Request.";
$headers = 'From: AFP Webmaster' . "\r\n" .
$headers = "MIME-Version: 1.0" . "\r\n" .
$headers = "Content-type:text/html;charset=iso-8859-1" . "\r\n" .
'Reply-To: AFP Webmaster' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
else {
$errTyp = "danger";
$errMSG = "Something went wrong, try again later...";
}
}
The code WORKS PERFECTLY on the following:
1. Storing the value on DB.
2. If i place a valid email like "name#gmail.com" in $to
What I want to happen now is assigning the value of the "reqEmail" from the database or the value from the textfield "remail" to $to.
So the email will go to the email who filled up the form.
i hope i made myself clear and understandable.
Thanks!
You're clearing your variables before sending the email, so PHP doesn't know where to send the email to. You need to place your "unset" functions after the PHP Mailer call. Try this:
if (!$error) {
move_uploaded_file($file_loc, $folder.$file);
$cuser = $userRow['userName'];
$res = mysql_query("SELECT * FROM users WHERE userId=".$_SESSION['user']);
$userRow = mysql_fetch_array($res);
$query = "INSERT INTO postoffers(postedby,reqName,reqEmail,reqHotel,reqOutlet,reqCnum,reqPostType,reqPostHead,reqPostDet,offerStarts,offerEnds,file,type,size) VALUES('$cuser','$rname','$remail','$rhotel','$routlet','$rcnum','$rposttype','$rposthead','$rpostdet','$rbdate','$redate','$file','$file_type','$file_size')";
$res = mysql_query($query);
if ($res) {
$to = ;
$subject = "Your Post Offer";
$message = "Thank you " . $cuser . " for the Post Request.";
$headers = 'From: AFP Webmaster' . "\r\n".
$headers .= "MIME-Version: 1.0" . "\r\n".
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n" . 'Reply-To: AFP Webmaster' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
$errTyp = "success";
$errMSG = "Successfully Posted!";
unset($rname);
unset($remail);
unset($rhotel);
unset($routlet);
unset($rcnum);
unset($rposttype);
unset($rposthead);
unset($rpostdet);
unset($rbdate);
unset($redate);
unset($file);
} else {
$errTyp = "danger";
$errMSG = "Something went wrong, try again later...";
}
}
I am making a database validation system. Upon validation, the handler is supposed to send the data to an email address, while simultaneously updating the data to another database. The values of id, name, board, query and rand are received from the previous page.
Now, with the given code, I am unable to update the table named 'answers' within my database. The line of code for this functionality is in bold.
<?php
$servername = "localhost";
$username = "root";
$password = '';
$dbname = "bsp";
$conn1 = new mysqli($servername, $username, $password, $dbname);
$id="";
$value = "";
$name = "";
$board = "";
$query="";
$id = $_POST['id'];
$name = $_POST['name'];
$board = $_POST['board'];
$query = $_POST['query'];
$rand = $_POST['rand'];
$value=$_POST['option'];
$to="";
$subject="";
$msg="";
$headers="";
if($value=='delete')
{
$sql="DELETE FROM rti WHERE ID=$id";
if ($conn1->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn1->error;
}
}
else if($value=='validate')
{
**$sql="INSERT INTO answers (name, board, query, rand) VALUES (\"$name\", \"$board\", \"$query\", \"$rand\")";**
if($board=='BRCA')
{
$to = 'email#gmail.com';
$subject = 'RTI Query: Do not reply to this email.';
$msg = "Your code is " . $rand . ".";
$msg .= " Visit localhost/BSP/landing.php and post the code, and subsequently your answer.";
$headers = 'From: contact#yoursite.com';
mail($to, $subject, $msg, $headers);
}
else if($board=='BSW')
{
$to = 'email#rediffmail.com';
$subject = 'RTI Query: Do not reply to this email.';
$msg = $query;
$headers = 'From: contact#yoursite.com';
mail($to, $subject, $msg, $headers);
}
else if($board=='BSA')
{
$to = 'email#iitd.ac.in';
$subject = 'RTI Query: Do not reply to this email.';
$msg = $query;
$headers = 'From: contact#yoursite.com';
mail($to, $subject, $msg, $headers);
}
else if($board=='BSP')
{
$to = 'email#gmail.com';
$subject = 'RTI Query: Do not reply to this email.';
$msg = $query;
$headers = 'From: contact#yoursite.com';
mail($to, $subject, $msg, $headers);
}
else if($board=='BHM')
{
$to = 'email#gmail.com';
$subject = 'RTI Query: Do not reply to this email.';
$msg = $query;
$headers = 'From: contact#yoursite.com';
mail($to, $subject, $msg, $headers);
}
}
if(mail($to, $subject, $msg, $headers)==TRUE)
{
echo "The mail was sent successfully.";
}
$conn1->close();
?>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am trying to send an email using php but unable to do it, whereas I am getting data into MySQL database.
I have posted my whole code, please check and let me know where's the mistake.
$objConnect = mysql_connect("localhost","username","pwd");
$objDB = mysql_select_db("database");
$strName = $_POST["name"];
$strEmail = $_POST["email"];
$to = $strEmail;
$subject = 'the subject';
$message = 'hello';
$headers = 'From: mymail#gmail.com' . "\r\n" .
'Reply-To: mymail#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$strSQL = "insert into data (name, email) VALUES ('".$strName."','".$strEmail."')";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
$arr['StatusID'] = "0";
$arr['Message'] = "Cannot save data!";
}
else
{
mail($to, $subject, $message, $headers);
$arr['StatusID'] = "1";
$arr['Message'] = "Data saved successfully";
}
mysql_close($objConnect);
echo json_encode($arr);
This code is really working ...
<?php
$to = 'to_email#gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: mymail#gmail.com' . "\r\n" .
'Reply-To: mymail#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$errLevel = error_reporting(E_ALL ^ E_NOTICE); // suppress NOTICEs
if(!mail($to, $subject, $message, $headers)){
error_reporting($errLevel);
}
?>
You have not added mail() function in your code then how will it send the mail and to send email from localhost it should be properly configured. Below code will work on the server.
$objConnect = mysql_connect("localhost","username","pwd");
$objDB = mysql_select_db("database");
$strName = $_POST["name"];
$strEmail = $_POST["email"];
$to = $strEmail;
$subject = 'the subject';
$message = 'hello';
$headers = 'From: mymail#gmail.com' . "\r\n" .
'Reply-To: mymail#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(!mail($to, $subject, $message, $headers)){
echo 'Mail cant be send';
}
else
{
$strSQL = "insert into data (name, email) VALUES ('".$strName."','".$strEmail."')";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
$arr['StatusID'] = "0";
$arr['Message'] = "Cannot save data!";
}
else
{
mail($to, $subject, $message, $headers);
$arr['StatusID'] = "1";
$arr['Message'] = "Data saved successfully";
}
echo json_encode($arr);
}
mysql_close($objConnect);
I am struggling with the following.When a user fills in a form looking like this, the inquiry gets sent to us to follow up the lead, but I need to find a way to modify my email script to send a confirmation email to the user aswell
My email script looks like this:
MY QUESTION HOW DO I MODIFY THIS TO SEND A THANK YOU CONFIRMATION TO THE USER
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$eventType = $_POST['eventType'];
$nrGuests = $_POST['nrGuests'];
$state = $_POST['state'];
$suburb = $_POST['suburb'];
$msg = $_POST['msg'];
$refferal_page = $_POST['page'];
$ip = $_SERVER['REMOTE_ADDR'];
if(!isset($refferal_page)){
$refferal_page="Source Unknown";
}
$to_email = "unknown#yahoo.co.nz"; //Recipient email
//TODO Sanitize input data using PHP filter_var().
$suburb = filter_var($_POST["suburb"], FILTER_SANITIZE_STRING);
$subject = "You Have a New Booking!";
//Add booking INFO here;
$message = "A new Enquiry has been received from http://www.xxxxx.com.au. Please find details below and follow up:";
//email body
$message_body = $message."\r\n\r\n".$name."\r\nEmail : ".$email."\r\nPhone Number : ". $mobile."\r\nEvent Type: ".$eventType."\r\nNumber Guests:".$nrGuests."\r\nState: ".$state."\r\nSuburb:".$suburb."\r\nIP ADDRESS:".$ip."\r\nMessage:".$msg."\r\nReferal Page Source:".$refferal_page;
//proceed with PHP email.
$headers = 'From: '.$name.'' . "\r\n" .
'Reply-To: '.$email.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$send_mail = mail($to_email, $subject, $message_body, $headers);
if($send_mail)
{
echo '<h1 class="page-header">Enquiry Successfully submitted</h1>';
}
else if(!$send_mail){
echo'<h1 class="page-header" style="color:RED">OOPS...SOMETHING WENT WRONG, PLEASE TRY AGAIN!</h1>';
}
}//server request method
else{
echo'<h1 style="color:red">SUBMIT A FORM PLEASE!</h1>';
}
?>
EMAIL THAT COMES TO US
A new Inqury has been received from www.xxxx.com.au. Please find details below and follow up:
FROM: Ryan XXX
Email : aass#testms.com
Phone Number : 334533
Event Type: Aniversary
Nr Guests: 34
State: Melbourne
Suburb: XYZ
IP ADDR: 162.111.255.111
MSG: this is a test. please disregard
Referal Page Source:aniversary
Obviously I dont want user to see this I just want to add something like "Thank you we will get back to you soon"
Any idea how I can modify the above script for us to get inquiry form but also for user to get an confirmation email?
Any help greatly appreciated
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$eventType = $_POST['eventType'];
$nrGuests = $_POST['nrGuests'];
$state = $_POST['state'];
$suburb = $_POST['suburb'];
$msg = $_POST['msg'];
$refferal_page = $_POST['page'];
$ip = $_SERVER['REMOTE_ADDR'];
if(!isset($refferal_page)){
$refferal_page="Source Unknown";
}
$to_email = "unknown#yahoo.co.nz"; //Recipient email
//TODO Sanitize input data using PHP filter_var().
$suburb = filter_var($_POST["suburb"], FILTER_SANITIZE_STRING);
$subject = "You Have a New Booking!";
//Add booking INFO here;
$message = "A new Enquiry has been received from http://www.xxxxx.com.au. Please find details below and follow up:";
//email body
$message_body = $message."\r\n\r\n".$name."\r\nEmail : ".$email."\r\nPhone Number : ". $mobile."\r\nEvent Type: ".$eventType."\r\nNumber Guests:".$nrGuests."\r\nState: ".$state."\r\nSuburb:".$suburb."\r\nIP ADDRESS:".$ip."\r\nMessage:".$msg."\r\nReferal Page Source:".$refferal_page;
//proceed with PHP email.
$headers = 'From: '.$name.'' . "\r\n" .
'Reply-To: '.$email.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$send_mail = mail($to_email, $subject, $message_body, $headers);
if($send_mail)
{
echo '<h1 class="page-header">Enquiry Successfully submitted</h1>';
$EmailTo = $email;
$subject = "recipient subject";
$message_body = "Hi ".$name."recipient message";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: yourname<$youremail>\n";
$send_cust_mail = mail($to_email, $subject, $message_body, $headers);
}
else if(!$send_mail){
echo'<h1 class="page-header" style="color:RED">OOPS...SOMETHING WENT WRONG, PLEASE TRY AGAIN!</h1>';
}
}//server request method
else{
echo'<h1 style="color:red">SUBMIT A FORM PLEASE!</h1>';
}
?>
Let say I have a class, for example:
class User{
function callname(){
$user = $_SESSION['id'];
$query = ("SELECT * FROM user WHERE user.id='$user'");
while ($result=mysql_fetch_array($query)){
echo ($result['username']);}}}
And then, make instance for User object:
$user = new User;
Code to send mail:
if($_SERVER["REQUEST_METHOD"] == "POST"){
$username = trim($_POST['username']);
$check = mysql_num_rows(mysql_query("SELECT * FROM user WHERE username='$username'"));
if ($check==TRUE){
$name = $user->callname();
$to = "myemail#domain.com";
$subject = "Example Subject";
$headers = "From: My Domain".'\r\n'.
"MIME-Version: 1.0".'\r\n'.
"Content-Type: text/html; charset=ISO-8859-1".'\r\n'.
'X-Mailer: PHP/' . phpversion();
$message = "Hai $name, this is the new message.";
mail($to, $subject, $message, $headers);
} else {
?>
<script type="text/javascript">
alert("Sorry, username not exist !");
</script>
<?php
}
}
Mail function was working correctly and I have received an email too. The problem is
$name didn't print the name of user in the email. I've tried this $name = $user->callname(); on different page without the if() and it was working.
\r\nMIME-Version: 1.0 and so on was print in the From header.
I think you need to return $result['username'] instead of echoing it.
For special characters be read as such you need them in double quotes (").
A attempt to correct your code:
class User{
function callname(){
$user = $_SESSION['id'];
$query = mysql_query("SELECT * FROM user WHERE user.id='$user'");
while ($result=mysql_fetch_array($query)){
return $result['username'];}}}
Next part:
if($_SERVER["REQUEST_METHOD"] == "POST"){
$username = mysql_real_escape_string(trim($_POST['username']));
$check = mysql_num_rows(mysql_query("SELECT * FROM user WHERE username='$username'"));
if ($check==TRUE){
$name = $user->callname();
$to = "myemail#domain.com";
$subject = "Example Subject";
$headers = "From: My Domain"."\r\n".
"MIME-Version: 1.0"."\r\n".
"Content-Type: text/html; charset=ISO-8859-1"."\r\n".
'X-Mailer: PHP/' . phpversion();
$message = "Hai $name, this is the new message.";
mail($to, $subject, $message, $headers);
} else {
?>
<script type="text/javascript">
alert("Sorry, username not exist !");
</script>
<?php
}