I want to send BCC email along with Recipient in Contact form. How I can include BCC in my code? I am not seeing error in below code but it won't send you email to BCC or Recipient. If I remove BCC, it will send you to Recipient.
$recipient = "xjkfak223#gmail.com";
// Set the email subject.
$subject = "New contact from $name";
// Build the email content.
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Phone: $phone\n\n";
$email_content .= "Message: $message\n";
$email_content .= "$subscribe: Yes\n";
// Build the email headers.
$email_headers = "From: $name <$email>";
$email_headers = "BCC: xy123#gmail.com";
// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers)) {
// Set a 200 (okay) response code.
http_response_code(200);
echo "Thank You for Contacting Us.";
}
You're overwriting the variable.
If you add .= it will append the string. I suppose you need a comma new line between too.
$email_headers = "From: $name <$email>\n";
$email_headers .= "BCC: xy123#gmail.com";
Related
I finally manged to get my contact form on my website to work, however, when it comes through via email, it's very plain. Would it be possible to try and get some words bolded under the email content settings? I'm new to all of this and I'm slowly learning but I've been stuck on this one for hours.
Content Code:
// Build the email content.
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Company: $company\n\n";
$email_content .= "Message:\n$message\n";
Full Mailer.php code:
<?php
// Only process POST requests.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form fields and remove whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = trim($_POST["message"]);
$company = trim($_POST["company"]);
// Check that data was sent to the mailer.
if ( empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
http_response_code(400);
echo "Oops! There was a problem with your submission. Please complete the form and try again.";
exit;
}
// Set the recipient's email address.
// FIXME: Update this to your desired email address.
$recipient = "(my company email here)";
// Set the email subject.
$subject = "Website Query - $name $company";
// Build the email content.
$email_content = "<strong>Name:</strong> $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Company: $company\n\n";
$email_content .= "Message:\n$message\n";
// Build the email headers.
$email_headers = "From: $name <$email>";
// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers)) {
// Set a 200 (okay) response code.
http_response_code(200);
echo "Thank You! Your message has been sent.";
} else {
// Set a 500 (internal server error) response code.
http_response_code(500);
echo "Oops! Something went wrong and we couldn't send your message.";
}
} else {
// Not a POST request, set a 403 (forbidden) response code.
http_response_code(403);
echo "There was a problem with your submission, please try again.";
}
You would use standard html syntax.
So, send an email with bold text in it, you'd simply send
<b>Bold Text</b>
In your case, do this
$temp_message = trim($_POST["message"]);
//Find which part you want to bold or do this to make the whole thing bold.
$message = "<b>"+$temp_message+"</b>"
How can i hide reply to header , from mail boxes,
For example , i send a mail from test#domain.com with reply to as notification#domain.com, and receiver open the mail and click on reply, i want the receiver to see from email which is test#domain.com in reply, instead of reply to which is notification#domain.com, and also the reply will come notification#domain.com .
Any help. My code below
<?php
if(#isset($_POST['send'])){
$From = $_POST['From'];
$Subject = $_POST['Name'];
//$Message = $_POST['Message'];
$Message = "";
$Reply= "notification#domain.com";
$Emails = $_POST['Emails'];
$toname = $_POST['toname'];
$Name = $_POST['Name'];
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type:text/html;charset=UTF-8\r\n";
$headers .= "Reply-To: ".$Reply."\r\n";
$headers .= "From: ".$From."\r\n";
$headers .= "Hi<br>".$toname."\r\n";
$headers .= "<br><br>Are you today? <br><br><br><br>Thanks,<br>".$Name."<br><br>
Sent from my work office\r\n";
$Emails = explode("\r\n", $_POST['Emails']);
foreach($Emails as $email) {
mail($email,$Subject,$Message,$headers);
echo "<br>Sending Email from : name:".$Name.", email: ".$From.", to name: ".$toname.", email:".$email." => was successfully sent";
//echo "<br>Sending Email To : ".$email." => Done";
}
}
?>
I have a problem with my mail in php. I code form to send email. I receive email on gmail but I have other mail address and I can't get email on it.
I checked in spam and there is no email also.
Below is my code.
<?php
$emailErr = "";
$endMessage = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["email"])) {
$emailErr = "Proszę uzupełnić pole e-mail";
}
else if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$namesurname = $_REQUEST['name_surname'] ;
$email = $_REQUEST['email'] ;
$number = $_REQUEST['number'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$message = $subject . ": " . $message . " " . $number . " " . $namesurname . " " . $email;
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
mail("szafor#szafor.pl", "Zamówienie pomiaru",
$message, "From: formularz#szafortest.pl \r\n"."Content-Type: text/plain; charset=UTF-8\r\n");
$endMessage = "Dziękuję za przesłanie wiadomości.";
}
}
?>
One important thing to consider with sending mail is that you should at least have the return path of the message be an email address that is actually hosted on the server that you are sending from.
You can set the From and the Reply-To address as any address, but the return-path should be set to a valid email address hosted on your server. Let's say that you want the "reply" button to send back to "this_email#wherever.com" but the server you are using hosts email for "mydomain.com". Create an email account on your server, "info#mydomain.com" for example.
$recipient = "sendto#email.com";
$subject = "Test email";
$message = "This is the message.";
$headers .= "From: Your Name Here <any_email#wherever.com>\n\r";
$headers .= "Reply-To: Your Name Here <any_email#wherever.com>\n\r";
$headers .= "Return-Path: Your Name Here <info#mydomain.com>\n\r";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
$headers .="X-Mailer: PHP/" . phpversion() . "\r\n";
$headers .="MIME-Version: 1.0\r\n";
mail($recipient, $subject, $message, $headers);
I have found that the more valid header information that I provide, the more likely the email will be delivered. Right now these headers always work for me, and I have a scheduling program that is sending email to a hundred different email addresses every day. See if that works better for you.
I am trying to make a simple form that sends the user defined/entered email address a link to them.
Visitor > Enter Mail > Hit Send > Receives a mail with a link
But I am battling to make it work.
$headers = "From: Siddharth Jain <email>\r\n";
$headers .= "Reply-To: Siddharth Jain <email>\r\n";
$headers .= "Return-Path: email\r\n";
$headers .= "Bcc: Siddharth Jain <email>\r\n";
$headers .= "PHP/" . phpversion();
$to = $_REQUEST['email'];
$subject="";
$mailcontent='Codeword: '.$_POST["text_box"];
mail($to, $subject, $mailcontent, $headers);
Replace "email" with your email and "Siddharth Jain" with the name you need to display in that email.
thanks Mitali Mehta :)
Got this to work.
<?php
// Contact subject
$subject ="mail subject";
// Details
$message="$detail";
// Mail of sender
$mail_from="no-reply#domain.com";
// From
$header="from: no-reply#domain.com";
// Enter your email address
$to = $_REQUEST['customer_mail'];
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
header("Location:http://www.domain.com/");
}
else {
echo "ERROR";
}
?>
in case someone else wants it :)
also this sends me a copy of the request too.
Please advise if the form validation script below is secure enough to avoid most types (all types?) of contact form exploits? I ahve found this script online, added some extra php finctions in hope to make it safer, but not complitely sure if it is good for the purpose.
if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
// Get the form fields and remove whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = trim($_POST["message"]);
// Check that data was sent to the mailer.
if ( empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
//http_response_code(400);
echo "Oops! There was a problem with your submission. Please complete the form and try again.";
exit;
}
// Set the recipient email address.
// FIXME: Update this to your desired email address.
$recipient = "email_here";
// Set the email subject.
$subject = "New contact from $name";
// Build the email content.
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Message:\n$message\n";
// Build the email headers.
$email_headers = "MIME-Version: 1.0\r\n";
$email_headers .= "Content-type: text/html; charset=utf-8\r\n";
$email_headers .= "From: $name <$email>\r\n";
$email_headers .= "Reply-To: $email\r\n";
$email_headers .= "Return-Path: $email\r\n";
$email_headers .= "Organization: Bilingual Counselling\r\n";
// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers)) {
// Set a 200 (okay) response code.
//http_response_code(200);
echo "Thank You! Your message has been sent.";
} else {
// Set a 500 (internal server error) response code.
//http_response_code(500);
echo "Oops! Something went wrong and we couldn't send your message.";
}
}
It's not safe. For example you don't do anything with $message - you should probably use strip_tags() function here. Now you put anything that this variable holds straight into e-mail content.