Accept and Decline button is not working in mail - php

I am sending a mail after user submits form to approve are disapprove the data through link in mail. Here is the code:
$subject = 'User needs approval';
$message = 'The user $empname needs your approval' .
'----------------------------------- ' . "\r\n" .
'Accept: ' . $accept_link . "\r\n" .
'Decline: ' . $decline_link . "\r\n";
$_headers = 'From:admin#yourwebsite.com' . "\r\n"; // Set FROM headers
//mail($supemail, $subject, $message, $headers); // Send the email
fnMail($supemail,"mailb#mail.com"," Web master","reimbursement Form",$message);
The link to accept and decline is:
$accept_link = "http://communique/elegant-contact-form/quick-contact/ajax/approval.php?e=" . $empemail . "&h=" . hash('sha512', 'ACCEPT');
$decline_link = "http://communique/elegant-contact-form/quick-contact/ajax/approval.php?e=" . $empemail . "&h=" . hash('sha512', 'DECLINE');
and here is the approval.php file:
$hash = $_GET['h'];
$email = $_GET['e'];
if($hash == hash('sha512', 'ACCEPT')){
$res=execQuery('oth','update form set approved=1 where empemail="$email"');
if(count($res)>0){
fnMail($email,"mk.web#mattsenkumar.com","MattsenKumar Web master","Contact Front registration",'APPROVED');
}
}else if($hash == hash('sha512', 'DECLINE')){
fnMail($email,"mk.web#mattsenkumar.com","MattsenKumar Web master","Contact Front registration",'DECLINE');
}
But I got the mail like this:
The user $empname needs your approval----------------------------------- Accept: Decline:

This is day-1 basic PHP syntax: variables are not interpolated into single-quoted strings. Read the docs, do this:
$message = "The user $empname needs your approval" .
For the accept and deny links to be included in the message you must define them before you use them, like this:
$accept_link = "http://communique/elegant-contact-form/quick-contact/ajax/approval.php?e=" . $empemail . "&h=" . hash('sha512', 'ACCEPT');
$decline_link = "http://communique/elegant-contact-form/quick-contact/ajax/approval.php?e=" . $empemail . "&h=" . hash('sha512', 'DECLINE');
$message = "The user $empname needs your approval" .
'----------------------------------- ' . "\r\n" .
'Accept: ' . $accept_link . "\r\n" .
'Decline: ' . $decline_link . "\r\n";

$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
Try setting the headers
or check this below stackoverflow link
hope this will help
PHP mail() - How to put an html link in an email?

Related

Send multiple images in email using mail()

I stored the images in url format in database.now i want to send mail with multiple images using mail() in php
$sql11 = "SELECT `photo_id`, `project_id`, `map_id`, `map_flag`, `user_id`, `photo_path`, `pdf_path`, `created_at`, `modified_at` FROM `photos` WHERE map_flag='Task' and map_id='$task_id'";
$rl = $conn->query($sql11);
while ($res11 = mysqli_fetch_assoc($rl)) {
$array[] = [$res11['photo_path']];
}
$str = implode(',', $array);
$message = $message_content . "\n" . "\n" . "\n" . $message1 . "\n" . $message2 . "\n" . $message3 . "\n" . $message4 . "\n" . $message5 . "\n" . $message6 . "\n" . $array . "\n" . $message8 . "\n";
$from = "123#test.com";
$headers = 'From: ' . $from . "\r\n";
$result = mail($to, $subject, $message, $headers);
First off, you need to tell the email app that this is html. This can be done by adding the line
$headers .= "Content-type: text/html; charset=UTF-8";
Next, what is photo_path? Does it also include the full url or a relative url? You need to set the full url i.e. http://example.com/{$res11['photo_path']}

Email form is messing up UTF-8 text [duplicate]

This question already has answers here:
How to send UTF-8 email?
(3 answers)
Closed 3 years ago.
I have a PHP form on my website. It collects text strings from HTML input elements, then sends the text to my mailbox. However, when people type in text in other languages, the email appears garbled. The text appears to be okay in the Web browser. There's even some JavaScript code that gets/sets some of these form fields, and seems to do so correctly.
Maybe the PHP code is not treating the text as unicode? Or the text gets sent to my mailbox using the wrong encoding? I would appreciate some help, thanks.
I have already added
header("Content-Type: text/html; charset=utf8");
to the top of the PHP files.
Here is a part of the PHP form that gets the inputted values using POST.
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$titletxt = $_POST["titletxt"];
$titleurl = $_POST["titleurl"];
$legend = $_POST["legend"];
$command = $_POST["command"];
$binding = $_POST["binding"];
$layout = $_POST["layout"];
Here is a part of the PHP form that emails me the text:
mail
(
"blahblah#blah.com",
"VGKD Bindings Submission",
"NAME:\t\t" . $name . "\n" .
"EMAIL:\t\t" . $email . "\n" .
"MESSAGE:\t" . $message . "\n" .
"GAME TITLE:\t" . $titletxt . "\n" .
"GAME URL:\t" . $titleurl . "\n" .
"LAYOUT:\t\t" . $layout . "\n\n" .
"LEGENDS:\n" . $legend . "\n\n" .
"COMMANDS:\n" . $command . "\n\n" .
"BINDINGS:\n" . $binding . "\n\n"
);
Please, try to add utf-8 charset header to your mail function, for example
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <example#example.com>' . "\r\n";
$headers .= 'Cc: example#example.com' . "\r\n";
mail
(
"blahblah#blah.com",
"VGKD Bindings Submission",
"NAME:\t\t" . $name . "\n" .
"EMAIL:\t\t" . $email . "\n" .
"MESSAGE:\t" . $message . "\n" .
"GAME TITLE:\t" . $titletxt . "\n" .
"GAME URL:\t" . $titleurl . "\n" .
"LAYOUT:\t\t" . $layout . "\n\n" .
"LEGENDS:\n" . $legend . "\n\n" .
"COMMANDS:\n" . $command . "\n\n" .
"BINDINGS:\n" . $binding . "\n\n",
$headers
);
The header() function sends a raw HTTP header to a client browser, but mail function with the variable $headers sends headers to email.

MIME email, blank message body

So I tried searching but couldn't find an answer that I was able to apply to my code. I have had a developer updating a page for me and these emails come through on my mobile device, but the body is always blank on my computer email, Thunderbird. The code in question looks like this:
$mailBody = "Dog Registration Form Data" . PHP_EOL . $strDogCName . ";" . $strDogFName . ";" . $strBreed . ";" . $strGender . ";" . $strHt . ";" . $strBdmm . "/" . $strBddd . "/" . $strBdyy . ";" . $strFName . ";" . $strLName . ";" . $strAddr1 . ";" . $strCity . ";" . $strState . ";" . $strZip . ";" . $strCountry . ";" . $strPhone . ";" . $strEMail . ";" . $member_num. ";" . $dog_num;
// injection test before setting message headers
$sender_name = $strFName . " " . $strLName;
$sender_name = injection_test($sender_name);
$sender_email = injection_test($strEMail);
// Set headers and send. This should be moved to a reusable function
$mime_boundary = md5(time());
$headers = '';
$msg = '';
$headers .= 'From: ' . $sender_name . ' <' . $sender_email . '>' . PHP_EOL;
$headers .= 'Reply-To: ' . $sender_name . ' <' . $sender_email . '>' . PHP_EOL;
$headers .= 'Return-Path: ' . $sender_name . ' <' . $sender_email . '>' . PHP_EOL;
$headers .= "Message-ID: <" . time() . "cform#" . $_SERVER['SERVER_NAME'] . ">" . PHP_EOL;
$headers .= 'X-Sender-IP: ' . $_SERVER["REMOTE_ADDR"] . PHP_EOL;
$headers .= "X-Mailer: PHP v" . phpversion() . PHP_EOL;
$headers .= 'MIME-Version: 1.0' . PHP_EOL;
$headers .= 'Content-Type: multipart/related; boundary="' . $mime_boundary . '"';
$msg .= '--' . $mime_boundary . PHP_EOL;
$msg .= 'Content-Type: text/plain; charset="UTF-8"' . PHP_EOL;
$msg .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;
$msg .= $mailBody . PHP_EOL . PHP_EOL;
$msg .= '--' . $mime_boundary . '--' . PHP_EOL . PHP_EOL;
ini_set('sendmail_from', $sender_email);
$msg = "Thank you for registering with NADAC.". PHP_EOL. " Here is the info you provided." . PHP_EOL ."Callname: ". $strDogCName . PHP_EOL. "Registered Name: " . $strDogFName . PHP_EOL . "Breed: " . $strBreed .PHP_EOL . "Gender: " . $strGender .PHP_EOL . "Height: " . $strHt .PHP_EOL . "Birthday: " . $strBdmm . "/" . $strBddd . "/" . $strBdyy .PHP_EOL . "Owner First Name: " . $strFName .PHP_EOL . "Owner Last Name: " . $strLName .PHP_EOL . "Address: " . $strAddr1 .PHP_EOL . "City: " . $strCity .PHP_EOL . "State: " . $strState .PHP_EOL . "Zip Code: " . $strZip .PHP_EOL . "Country: " . $strCountry .PHP_EOL . "Phone: " . $strPhone . PHP_EOL . "Email: " . $strEMail .PHP_EOL . "Associate number: " . $member_num. PHP_EOL . "Dog Number: " . $dog_num;
$mailSubject = "Thank you for registering.";
$send_status = mail($mailTo, $mailSubject, $msg, $headers);
$mailTo = $strEMail;
mail($mailTo, $mailSubject, $msg, $headers);
ini_restore('sendmail_from');
// should check send_status here and do something - TODO
unset($_POST['submitted']);
// Done with the mail, display confirmation
I'm sure it's something simple that I'm just missing. But I can't find it, and the programmer working on it doesn't seem to believe the issue. I don't believe it's a local issue with my email provider.
Have you tried with Content-Type: multipart/alternative instead of 'multipart/related'?
The weird thing if the double mail() calling and $send_status to unknown $mailTo var

Php Form - Why are all fields required?

I have a contact form that will only submit if all the fields are completed. I don't want this as many fields are optional. I believe it has to do with this part of my code, but I am unsure how to change it and removing it will post the form automatically when the page opens.
if (isset($_POST['first_name'], $_POST['last_name'], $_POST['address'], $_POST['address_line_2'], $_POST['city_state_zip'], $_POST['phone_number'], $_POST['email_address'], $_POST['bedrooms'], $_POST['baths'], $_POST['square_feet'], $_POST['basement'], $_POST['garage'], $_POST['house_style'], $_POST['price_range'], $_POST['construction'], $_POST['heat'], $_POST['features'], $_POST['comments']))
For context here is the rest of the code.
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
include_once "/usr/share/pear/Swift/swift_required.php";
// Check if the form has been posted
if (isset($_POST['first_name'], $_POST['last_name'], $_POST['address'], $_POST['address_line_2'], $_POST['city_state_zip'], $_POST['phone_number'], $_POST['email_address'], $_POST['bedrooms'], $_POST['baths'], $_POST['square_feet'], $_POST['basement'], $_POST['garage'], $_POST['house_style'], $_POST['price_range'], $_POST['construction'], $_POST['heat'], $_POST['features'], $_POST['comments'])) {
// The email address the email will be sent to
$to = 'emailaccount#website.com';
// Set the from address for the email
$from = 'emailaccount#website.com';
$headers = "Reply-To: ".$_POST["email"]."\r\n";
// The email subject
$subject = 'Contact Form Submission';
// Build the body of the email
$mailbody = "The contact form has been filled out.\n\n"
. "first_name: " . $_POST['first_name'] . "\n"
. "last_name: " . $_POST['last_name'] . "\n"
. "address: " . $_POST['address'] . "\n"
. "address_line_2: " . $_POST['address_line_2'] . "\n"
. "city_state_zip: " . $_POST['city_state_zip'] . "\n"
. "phone_number: " . $_POST['phone_number'] . "\n"
. "email_address: " . $_POST['email_address'] . "\n"
. "bedrooms: " . $_POST['bedrooms'] . "\n"
. "baths: " . $_POST['baths'] . "\n"
. "square_feet: " . $_POST['square_feet'] . "\n"
. "basement: " . $_POST['basement'] . "\n"
. "garage: " . $_POST['garage'] . "\n"
. "house_style: " . $_POST['house_style'] . "\n"
. "price_range: " . $_POST['price_range'] . "\n"
. "construction: " . $_POST['construction'] . "\n"
. "heat: " . $_POST['heat'] . "\n"
. "features: " . $_POST['features'] . "\n"
. "comments:\n" . $_POST['comments'];
// Create the mail transport
$transport = Swift_SmtpTransport::newInstance('smtp.domainhere.com', 587);
$transport->setUsername('emailaccount#website.com');
$transport->setPassword('123456');
$swift = Swift_Mailer::newInstance($transport);
// Create the mail
$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setTo($to);
$message->setBody($mailbody);
// Send the mail
$result = $swift->send($message);
}
if ($result)
{
header('Location: http://www.domainhere.com/thankyou.html'); }
?>
Your thoughts would be greatly appreciated.
This line:
if (isset($_POST['first_name'], $_POST['last_name'], $_POST['address'], $_POST['address_line_2'], $_POST['city_state_zip'], $_POST['phone_number'], $_POST['email_address'], $_POST['bedrooms'], $_POST['baths'], $_POST['square_feet'], $_POST['basement'], $_POST['garage'], $_POST['house_style'], $_POST['price_range'], $_POST['construction'], $_POST['heat'], $_POST['features'], $_POST['comments']))
requires everything there to be filled in.

Include date, IP and HTTP_HOST in Support form

I am trying to include the current date, senders IP and Host in my contact form submission.
This is the code:
<?php
if( isset($_POST['name']) )
{
$to = 'info#mydomain.com'; // Replace with your email
$subject = 'Contact Form Submission'; // Replace with your $subject
$headers = 'From: ' . $_POST['email'] . "\r\n" . 'Reply-To: ' . $_POST['email'];
$date = date('M jS, Y # h:i a');
$IP = $_SERVER['REMOTE_ADDR'];
$Host = $_SERVER['HTTP_HOST'];
$message = 'Name: ' . $_POST['name'] . "\n" .
'E-mail: ' . $_POST['email'] . "\n" .
'Subject: ' . $_POST['subject'] . "\n" .
'Department: ' . $_POST['department'] . "\n" .
'Message: ' . $_POST['message'] . "\n" .
'Date: ' . $_POST['$date'] . "\n" .
'IP: ' . $_POST['$IP'] . "\n" .
'Host: ' . $_POST['$Host'];
mail($to, $subject, $message, $headers);
if( $_POST['copy'] == 'on' )
{
mail($_POST['email'], $subject, $message, $headers);
}
}
?>
The Email is received, but without Date, IP and Host. Any help would be greatly appreciated.
You have already stored(ip, date etc.) in variables so use these variables for mail. also these values are not exists in POST data so try to replace
'Date: ' . $_POST['$date'] . "\n" .
'IP: ' . $_POST['$IP'] . "\n" .
'Host: ' . $_POST['$Host'];
to
'Date: ' . $date . "\n" .
'IP: ' . $IP . "\n" .
'Host: ' . $Host;
You should attach like this(bellow) because $date, $IP and $Host are not transmitted in a post request:
$createdDate = new DateTime();
$date= $createdDate->format('d.m.Y H:m');
$message = 'Name: ' . $_POST['name'] . "\n" .
'E-mail: ' . $_POST['email'] . "\n" .
'Subject: ' . $_POST['subject'] . "\n" .
'Department: ' . $_POST['department'] . "\n" .
'Message: ' . $_POST['message'] . "\n" .
'Date: ' . $date. "\n" .
'IP: ' . $IP. "\n" .
'Host: ' . $Host;

Categories