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);
}
Related
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 a problem sending an email to the following domains:
#yahoo.com,
#hotmail.com, and
#mncgroup.com
using the PHP mail() function. But there's no problem if I send an email to #gmail.com
Is there something wrong with my code?
$to = "$email";
$subject = "[NO-REPLY]Confirmation Account Pengaduan Keluhan I-news Tv";
$header = "From: inewsit#mncgroup.com \r\n";
$header .= "Akun Information MNC Biro";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Selamat Akun Anda Sudah Aktif</h1>
<p>Detail Account Username :</p>
<br>Your username : $hasil[username]
<br> Your Full Name : $hasil[nama]
<br> Your Email Address : $hasil[email]
<br> Your Status Akun : $status_akun1
<br> Your Lever authentication : $hasil[level]
<br> Your Register Date : $hasil[tanggal_register]
<br>Login sekarang ke : <a href='http://mncgroup.hol.es'><i>http://mncgroup.hol.es</i></a>
</body>
</html>";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
?>
<div class="alert alert-success alert-dismissable">
<a class="panel-close close" data-dismiss="alert">x</a>
<center>Silahkan Cek <strong>Email</strong> Anda</center>
</div>
<?php
when i run this code and i try to send email to 3 domain above, the message does not get into the email
First, try this in your code:
echo (mail($to, $subject, $message, $headers)) ? 'Message sent!' : 'Message not sent!';
Because of mail() function returns true or false depending on whether the mail was accepted for delivery. I recommend you check your spam folder at those addresses. I have heard that mail sent from the free servers due to the amount of abuse goes directly to spam.
Try this sample code for checking purpose:
<?php
$to = 'ANY EMAIL#yahoo.com';
$subject = 'ANY SUBJECT';
$message = 'ANY MESSAGE';
$headers = 'From: check#check.com' . "\r\n" .
'Reply-To: no-reply#check#check.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
echo (mail($to, $subject, $message, $headers)) ? 'Message sent!' : 'Message not sent!';
?>
Try replacing all occurrences of \r\n with PHP_EOL. Something like this:
$to = "$email";
$eol = PHP_EOL;
$subject = "[NO-REPLY]Confirmation Account Pengaduan Keluhan I-news Tv";
$header = "From: inewsit#mncgroup.com $eol";
$header .= "Akun Information MNC Biro";
$headers .= "MIME-Version: 1.0$eol";
$headers .= "Content-Type: text/html; charset=ISO-8859-1$eol";
See if that changes anything.
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
Forgive me, I am new at this and the different php I have tried hasn't really worked at all. I've found examples for Natural Language forms, but none with working PHP and I'm familiar with PHP when used with traditional forms, but I'm having problems putting the two together.
The general form layout goes like this:
My name is [your name].
Today, I am [whatchya gonna do?].
I'm doing this because [c'mon,why?].
It's important that I [what you said you'd do] because [the big picture].
Shoot me an email with my awesome new declaration at [your email]
Button 1 (sends email)
Button 2 (copies all text and input fields to clipboard -- not as important right now)
Button 1, I want to send a copy to myself with a hard coded email address and also send a copy to the user with the email address they've entered.
This is a little messy right now, as I am simply trying to get it to work... again, I have no included PHP because at this point -- I've confused myself so much that I don't know what to include.
<form method="post" action="todayiam.php">
<div class="naturallanguageform">
<div class="nlfinner">
<p class="line">
<span class="copy">My name is </span>
<span class="inputcontainer"><input class="textinput" name="name" value="" placeholder="[your name]">.</span>
<span class="copy">Today, I am </span>
<span class="inputcontainer"><input class="textinput" name="todayiam" value="" placeholder="[whatchya gonna do?]">.</span>
<span class="copy">I'm doing this because </span>
<span class="inputcontainer"><input class="textinput" name="why" value="" placeholder="[c'mon, why?]">.</span>
<span class="copy"> It's important that I </span>
<span class="inputcontainer"><input class="textinput" name="whatusaid" value="" placeholder="[what you said you'd do]"></span>
<span class="copy"> because </span>
<span class="inputcontainer"><input class="textinput" name="because" value="" placeholder="[the big picture]">.</span>
</p>
<span class="copy">Shoot me an email with my awesome new declaration at</span>
<span class="inputcontainer"><input class="textinput" name="email" value="" placeholder="[your email]"></span>
<p class="line">
<button class="button">Send to E-mail</button>
</p>
<p class="line">
<button class="button">Copy to post in comments</button>
</p>
</div>
</div>
</form>
Any assistance will be greatly appreciated.
Update:
<?php
// from the form
$name = trim(strip_tags($_POST['name']));
$email = trim(strip_tags($_POST['email']));
$message = htmlentities($_POST['todayiam']);
// set here
$subject = "Contact form submitted!";
$to = 'email#gmail.com';
$body = <<<HTML
$message
HTML;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
// send the email
mail($to, $subject, $body, $headers);
// redirect afterwords, if needed
header('Location: index.html');
?>
Another update
I have changed $headers = "From: $email\r\n"; to $headers = "From: email#gmail.com" . "\r\n" ; to set a static from address (my support email) and the email is still identifying as from CGI Mailer. I have verified that it's not a caching issue and the correct files are being used.
<?php
if (isset($_POST['name'], $_POST['todayiam'], $_POST['why'], $_POST['whatusaid'], $_POST['because'], $_POST['email']) {
// We enter this statement only if all the fields has been properly defined, this to avoid getting undefined index
$name = $_POST['name'];
$todayIam = $_POST['todayiam'];
$why = $_POST['why'];
$whatYouSaid = $_POST['whatusaid'];
$because = $_POST['because'];
$email = $_POST['email'];
// We define the variables for using in mail()
$to = 'email#gmail.com';
$to .= ', '.$email; // You wanted them to recieve a copy
$subject = "Contact form submitted!";
// You can put a lot more headers, check out the mail() documentation
$headers = "From: email#gmail.com" . "\r\n" ;
$headers .= "Content-type: text/html\r\n";
// Compose a $message from all the variables
$message = "My name is $name. ";
$message .= "Today, I am $todayIam.";
$message .= "I'm doing this because $why.";
$message .= "It's important that I $whatYouSaid";
$message .= "because $because.";
if (mail($to, $subject, $message, $header)) {
// Mail was successfully sent! Do something here
}
}
?>
Before you posted your answer, I was working on this script:
<?php
// from the form
$name = trim(strip_tags($_POST['name']));
$email = trim(strip_tags($_POST['email']));
$message = htmlentities($_POST['todayiam']);
// set here
$subject = "Contact form submitted!";
$to = 'email#gmail.com';
$body = <<<HTML
$message
HTML;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
// send the email
mail($to, $subject, $body, $headers);
// redirect afterwords, if needed
header('Location: index.html');
?>
The $email = trim(strip_tags($_POST['email'])); field was pulling the user's email and using it for the sent from as noted in the $header... so it was working fine. With the new script, that you posted, I can't get it to work with my hard coded email OR the user's email as the FROM. Initially, I really wanted to understand what the differences were between the script, why one worked and the other didn't, but now... I'd really just like my email to be hard coded as the FROM. I'll worry about the differences later. As I said before, I really have tried to get this to work in many different forms... I am sure it's something simple that I am over looking as a novice to PHP. Thanks.
Right, so after a bit of discussion from comments, I decided to post an answer instead, giving a bit more detail where it's more readable.
Your PHP code is missing the combination of all fields into $message. This can easily be done, as you can put a variable inside a string in PHP. I'll show you how. I'm also going to show you how you can avoid undefined indexes.
<?php
if (isset($_POST['name'], $_POST['todayiam'], $_POST['why'], $_POST['whatusaid'], $_POST['because'], $_POST['email']) {
// We enter this statement only if all the fields has been properly defined, this to avoid getting undefined index
$name = $_POST['name'];
$todayIam = $_POST['todayiam'];
$why = $_POST['why'];
$whatYouSaid = $_POST['whatusaid'];
$because = $_POST['because'];
$email = $_POST['email'];
// We define the variables for using in mail()
$to = 'email#gmail.com';
$to .= ', '.$email; // You wanted them to recieve a copy
$subject = "Contact form submitted!";
// You can put a lot more headers, check out the mail() documentation
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
// Compose a $message from all the variables
$message = "My name is $name. ";
$message .= "Today, I am $todayIam.";
$message .= "I'm doing this because $why.";
$message .= "It's important that I $whatYouSaid";
$message .= "because $because.";
if (mail($to, $subject, $message, $header)) {
// Mail was sucsessfullly sent! Do something here
}
}
?>
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>