This question already has answers here:
PHP E-mail Form Sender Name Instead Of E-mail?
(8 answers)
Closed 7 years ago.
//send email
$to = $_POST['email'];
$subject = "Welcome!";
$body = "Contains sensitive information that activates users so I've removed it.";
$additionalheaders = "From: <".SITEEMAIL.">\r\n";
$additionalheaders .= "Reply-To: ".SITEEMAIL."";
mail($to, $subject, $body, $additionalheaders);
Basically the above code successfully sends an email, and in the inbox it displays as noreply#mydomain which is fine, but I've noticed that other sites show actual names. Like messages from Facebook say Facebook not noreply#facebook.com. Is there a header I am missing to accomplish this?
EDITED TO SHOW ANSWER:
//send email
$to = $_POST['email'];
$subject = "Welcome!";
$body = "Contains sensitive information that activates users so I've removed it.";
$additionalheaders = "From: Name <".SITEEMAIL.">\r\n";
$additionalheaders .= "Reply-To: ".SITEEMAIL."";
mail($to, $subject, $body, $additionalheaders);
from: Jon Jones <Jon#Jones.com>
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed last year.
So i have my code and styling finished, first it worked tried a few times and it was sending mails.
the next day it was not sending any more, testing this on live server no localhost.
i need this code to work so clients can ask for information and we give them offers.
i have read it is better to use request method but have never used it, but if this may be a solution i will try it.
This is a test version of the website
https://www.two4u.be/test/index.php?page=contact
searching for a few days what the problem could be.
<?php
// email info to send
$to = "sammy#two4u.be"; // this is your Email address
$subject = "Offerte aanvraag website";
$from = $_POST['email']; // this is the sender's Email address
$name = $_POST['name'];
$straat = $_POST['straat'];
$gemeente = $_POST['gemeente'];
$nummer = $_POST['nummer'];
$tijdstip = $_POST['tijdstip'];
$systeemkeuze = $_POST['systeemkeuze'];
$budget = $_POST['budget'];
$termijn = $_POST['termijn'];
$extra = $_POST['extra'];
// create email headers
$headers = "From: Two 4 U <noreply#two4u.be>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
// create the html message
$message = "<html>
<body>
<h1> Offerte aanvraag via website</h1>
<h2> Gegevens van de klant</h2>
<p> <b>email:</b> $from <br>
<b>naam:</b> $name <br>
<b>Adres:</b> $gemeente <br>
$straat<br>
<b>Telefoon:</b> $nummer<br>
<b>Wanneer klant bereikbaar is:</b> $tijdstip<br>
<b>Welk systeem van ons:</b> $systeemkeuze<br>
<b>Klant budget hiervoor:</b> $budget<br>
<b>Binnen welke termijn:</b> $termijn<br>
</p>
<p> <b>Extra informatie:</b> $extra </p>
</body></html>";
// send email to user
if (!empty($_POST['mail'])){
mail($to, $subject, $message, $headers);
}
?>
In your submission form, there is no input box with the name="mail",
Hence change
if (!empty($_POST['mail'])){
mail($to, $subject, $message, $headers);
}
to
if (!empty($_POST['email'])){
mail($to, $subject, $message, $headers);
}
This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Online SpamAssassin evaluation / RFC conformant check [closed]
(1 answer)
Closed 4 years ago.
I'm using the mail() to send a simple email but from some reason everything I try it goes straight to spam, am I missing something here?
<?php
$to = "toemail#example.com";
$subject = "your subject";
$body = "<p>Your Body</p>";
$headers = "From: Sender Name <from#example.com>" . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail($to, $subject, $body, $headers);
?>
You need an additional 'Reply-to' Header to ensure that the sender e-mail address is the same as the reply-to mail address. This should solve your problem.
e.g $headers = "From: $from\r\nReply-to: $email";
Also make sure that your headers are seperated by \r\n
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I have a php script that sends an email from an HTML form. The issue is that the sender shows as CGI-Mailer in my inbox.
How can I set the sender address to be that of the sender and not CGI-Mailer?
<?php session_start();
if(isset($_POST['Submit'])) {
$youremail = 'info#complexny.com';
$fromsubject = $_POST['fname'];
$subject = $_POST['fname'];
$fname = $_POST['fname'];
$url = $_POST['url'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$headers = "From: $mail \n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$message = $_POST['message'];
$to = $youremail;
$subject = ''.$fromsubject. ' is interested in a project with you.';
$body = '
Client: '.$fname.'
Phone Number: '.$phone.'
URL: '.$url.'
E-mail: '.$mail.'
Message:
'.$message.'
';
echo "<p style='text-align:center'>Thank you for your feedback. We will be in contact shortly.<br/>Continue to <a href='/'>The Company/a></p>";
mail($to, $subject, $body);
} else {
echo "You must write a message. </br> Please go to <a href='/contact.php'>Contact Page</a>";
}
?>
You are not passing the additional_headers parameter to the mail function. Change the line with the call to mail to:
mail($to, $subject, $body, $headers);
I would suggest using PHPMailer rather than mail(). You can see how to do what you're after in the answer to this question: Setting replyTo field in email
Quoting from that question:
$this->phpmailer->AddReplyTo($replyEmail,$fromName); //this is email2#example.com
$this->phpmailer->SetFrom($fromEmail, $fromName); //this is email1#example.com
You can find more info on PHPMailer here: https://github.com/PHPMailer/PHPMailer
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I am having trouble with sending emails through PHP.
So I have a form which submits to a PHP script which sends an email:
<?php
$to = "myemail#email.com";
$subject = "[Contact Form]";
$name = $_POST["name"];
$contactNumber = $_POST["contactNumber"];
$email = $_POST["email"] ;
$message = $_POST["message"];
$body = "Someone has sent a new message from the contact form. \n \n Message from: " . $name . "\n Contact Number: ". $contactNumber ."\n Email: ". $email ."\n \n Message: ". $message;
if (mail($to, $subject, $body)) {
echo ("<p>Email successfully sent!</p>");
} else {
echo ("<p>Email delivery failed…</p>");
}
?>
And the email is sent fine when for example the message is one line such as:
"Hi there how is it going?"
And fine if it is multiple lines such as
"Hi there
how is it going?"
But when I try and type a message with a comma such as
Hello there,
how is it going?
It fails?
Is there a way I can just treat the whole thing as a string possibly? Would this also fail on any other characters or is this issue just because of the way I am writing the PHP script?
This might be an obvious fix but I am new to PHP so apologies! I have tried looking around for an answer but nothing seems to fix what I am looking for.
Thanks for any help!
Try using headers in your mail function, like this:
$headers = 'MIME-Version: 1.0\r\n';
$headers .= 'Content-type: text/html; charset=UTF-8\r\n';
mail($to, $subject, $body, $headers)
This question already has answers here:
Email Form more than 20 values
(3 answers)
Closed 6 years ago.
I am pretty new to all this and I need some help. This is the most basic mail function in PHP.
<?php
$headers = "Content-Type: text/html; charset=UTF-8";
$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$phone=$_POST['phone'];
$message=$_POST['message'];
$to ="maria#mkitra.com";
$subject2 = "Work";
mail($to, $subject2, $message, $headers, $name);
echo "Message Sent";
?>
It does send the email but my problem is that the mail function doesn't include either the user's email nor their phone number. How do I include them in the email?
I have tried
mail($to, $subject2, $message, $headers,$phone,$email $name);
But it says, the mail function can take maximum 5 parameters. I am confused.
You can use this
<?php
$to = $_POST['email']; //Whom you want to send
$from = "maria#mkitra.com"; //Your email id
$subject = $_POST['subject'];
$message = '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>yoursitename Message</title></head><body><span>Mobile</span><span>'.$phone.'</span><span>Name</span><span>'.$name.'</span></body></html>';
$headers = "From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
mail($to, $subject, $message, $headers);
echo "Message Sent";
Email only send to and email subject and email body and email type mean header. No send mobile number or name or any other things. If you add this then you add on your under email body