How to show Name in gmail inbox - PHP [duplicate] - php

This question already has answers here:
What is the format for e-mail headers that display a name rather than the e-mail?
(3 answers)
Closed 5 years ago.
EMAIL ID showing as Name in GMAIL INBOX. Please solve this issue.
using PHP code..
I want to see persons name.
MY CODINGS :
<?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["vname"]==""||$_POST["vemail"]==""||$_POST["sub"]==""||$_POST["msg"]==""){
echo "Fill All Fields..";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['vemail'];
// Sanitize E-mail Address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "Invalid Sender's Email";
}
else{
$subject = $_POST['sub'];
$message = $_POST['msg'];
$headers = 'From:'. $email . "\r\n"; // Sender's Email
$headers .= 'Cc:'. $email . "\r\n"; // Carbon copy to Sender
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// Send Mail By PHP Mail Function
mail("hameed.basha278#gmail.com", $subject, $message, $headers);
echo "Your mail has been sent successfuly ! Thank you for your feedback";
}
}
}
?>

Append the reply to header
$headers.='Reply-To: '.$_POST["vname"].'<"'.$email.'">'. "\r\n";

Related

Cc in php mail function not working where sender(From) and cc mail address is same [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 2 years ago.
I have a problem to send cc in php mail function to get feedback from the client.
Here is a simple php code-
<?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["name"]==""||$_POST["email"]==""||$_POST["sub"]==""||$_POST["msg"]==""){
echo "Fill All Fields..";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['email'];
// Sanitize E-mail Address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "Invalid Sender's Email";
}
else{
$subject = $_POST['sub'];
$name = $_POST["name"];
$message = $_POST['msg'];
$headers = 'From:'. $email . "\r\n"; // Sender's Email
$headers .= 'Cc:'. $email . "\r\n"; // Carbon copy to Sender
// Send Mail By PHP Mail Function
mail("xyz#example.com", $subject, $message, $headers);
echo "Your mail has been sent successfuly !";
}
}
}
?>
The mail is sent to the sender correctly but cc is not sent. Moreover when I fixed the email address in the Cc field i.e abc#xxx.com instead of $email, then Cc works. Help me to solve the problem.
I used to have tons of troubles with this. Try to install php mailer plugin
https://github.com/PHPMailer/PHPMailer.
This will also prevent future issues and save you loads of time when you realize you might want to get more out of sending an email.

Fasthosts shared platform PHP mail from web page issue -F

I am trying to send email from a web page hosted on a shared platform over at fasthosts. I cannot for the life of me get this to work, I had a much more extensive script which checked the validity of email etc, but now I've been reduced to using the basic example from fasthosts and it is still not working.
Please could someone take a look and let me now where I am going wrong...
<?php
// You only need to modify the following two lines of code to customise your form to mail script.
$email_to = "contact#mywebsite.co.uk"; // Specify the email address you want to send the mail to.
$email_subject = "Feedback from website"; // Set the subject of your email.
// This is the important ini_set command which sets the sendmail_from address, without this the email won't send.
ini_set("contact#mywebsite", $email_from);
// Get the details the user entered into the form
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
// Validate the email address entered by the user
if(!filter_var($email_from, FILTER_VALIDATE_EMAIL)) {
// Invalid email address
die("The email address entered is invalid.");
}
// The code below creates the email headers, so the email appears to be from the email address filled out in the previous form.
// NOTE: The \r\n is the code to use a new line.
$headers = "From: " . $email_from . "\r\n";
$headers .= "Reply-To: " . $email_from . "\r\n"; // (You can change the reply email address here if you want to.)
// Now we can construct the email body which will contain the name and message entered by the user
$message = "Name: ". $name . "\r\nEmail: " . $email . "\r\nMessage: " . $message ;
// Now we can send the mail we've constructed using the mail() function.
// NOTE: You must use the "-f" parameter on Fasthosts' system, without this the email won't send.
$sent = mail($email_to, $email_subject, $message, $headers, "-f" . $email_from);
// If the mail() function above successfully sent the mail, $sent will be true.
if($sent) {
$output = json_encode(array('type'=>'message', 'text' => 'Hi '.$name .' Thank you for contacting us.'));
die($output);
} else {
$output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
die($output);
}
?>

How do I integrate a "reply-to" in my php contact form? [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Send email with PHP from html form on submit with the same script
(8 answers)
Closed 5 years ago.
I am new to using php and I bought a website template with an integrated PHP contact form. When I receive email from customers and click to answer their question, it does not automatically use their email address to reply.
I know there is a "reply-to" that I can use in my code to make sure it will be using the customer address when clicking reply on my mail client. I just don't know how to use it.
Here is my code:
<?php
$to = 'info#webmaster.ca'; // Put in your email address here
$subject = "Formulaire de contact"; // The default subject. Will appear by default in all messages. Change this if you want.
// User info (DO NOT EDIT!)
$fname = stripslashes($_REQUEST['fname']); // sender's name
$email = stripslashes($_REQUEST['email']); // sender's email
$subject = stripslashes($_REQUEST['subject']);
$message = stripslashes($_REQUEST['message']);
// The message you will receive in your mailbox
// Each parts are commented to help you understand what it does exaclty.
// YOU DON'T NEED TO EDIT IT BELOW BUT IF YOU DO, DO IT WITH CAUTION!
$msg .= "Nom: ".$fname."\r\n\n"; // add sender's name to the message
$msg .= "Courriel: ".$email."\r\n\n"; // add sender's email to the message
$msg .= "Sujet: ".$subject."\r\n\n"; // add sender's name to the message
$msg .= "-----Commentaire------: ".$message."\r\n\n"; // add sender's email to the message
$msg .= "\r\n\n";
$mail = #mail($to, $subject, $msg, "De:".$email); // This command sends the e-mail to the e-mail address contained in the $to variable
if($mail) {
header("Location:index.php");
} else {
echo 'Envoi du message a échoué!'; //This is the message that will be shown when an error occured: the message was not send
}
?>
Just include the From or Reply-To header in your fourth parameter of mail().
Edit:
What you have now "De:".$email as stated in comments, is French for "From". Syntax is language specific and must be in English.

How do I send an email to an email address with an custom message [duplicate]

This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 5 years ago.
I wanted to send an email such as an confirmation email to an email address that the user has alredy specified in an input tag. Exampe:
I type in my email in an input tag and then I would recive an email at the address I entered in the input tag. Thanks, and If you know the answer could you possibly send me an code to paste in. (Im an php noob)
<?php
$recipient = $_POST['email']; //recipient
$email = "your#domain.com"; //senders e-mail adress
if((filter_var($email, FILTER_VALIDATE_EMAIL)) && ($robotest == "")) {
$Name = ($_POST['name']); //senders name
$mail_body = !!!----> WHAT DO I PUT HERE <----!!!!
$subject = "Porter Inquiry"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
mail($recipient, $subject, $mail_body, $header); //mail command :)
} else {
print "You've entered an invalid email address!";
}
?>

PHP mail form is being sent to Gmail spam [duplicate]

This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 7 years ago.
Can someone help me figure out why the below PHP is causing the email to be sent to Gmail spam? I tried following other directions for setting proper headers, but I still run into problems with my emails going into the spam filter in Gmail.
Any help would be appreciated!
<?php
//set validation error flag as false
$error = false;
//check if form is submitted
if (isset($_POST['submit']))
{
$name = trim($_POST['txt_name']);
$fromemail = trim($_POST['txt_email']);
$inquiry = trim($_POST['txt_inquiry']);
$message = trim($_POST['txt_msg']);
//name can contain only alpha characters and space
if (!preg_match("/^[a-zA-Z ]+$/",$name))
{
$error = true;
$name_error = "Please enter a real name";
}
if(!filter_var($fromemail,FILTER_VALIDATE_EMAIL))
{
$error = true;
$fromemail_error = "Please enter a valid email address";
}
if(empty($inquiry))
{
$error = true;
$inquiry_error = "Please enter your subject";
}
if(empty($message))
{
$error = true;
$message_error = "Please enter your message";
}
if (!$error)
{
//send mail
$toemail = "myemail#gmail.com";
$subject = "inquiry from visitor " . $name;
$body = "Here goes your Message Details: \n\n Name: $name \n From: $fromemail \n Inquiry: $inquiry \n Message: \n $message";
$headers = "From: $fromemail\n";
$headers .= "Reply-To: $fromemail";
$headers .= "Return-Path: $fromemail";
if (mail ($toemail, $inquiry, $body, $headers))
$alertmsg = '<div class="alert alert-success text-center">Message sent successfully. We will get back to you shortly!</div>';
else
$alertmsg = '<div class="alert alert-danger text-center">There is error in sending mail. Please try again later.</div>';
}
}
?>
It could be that your ip address of the server that you are sending the email with it used for other purposes that marked it as a spam address.
Most of the time when you add DKIM and SPF to your email server (if you use one) will solve this problem.
An essier solution would be to use an external mailing service so that you they can handle that for you
I often made the experience, that mails that are directly getting sent by PHP are recognized as SPAM...
my approach is now, to always use a SMTP-Server for sending those emails...
this post could help you!

Categories