PHP sending mail but with missing information [duplicate] - php

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

Related

Php mail function worked and then stopped [duplicate]

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);
}

Contact form email sends, but the message is in the subject [duplicate]

This question already has an answer here:
php form sending email, but not in correct way [closed]
(1 answer)
Closed 5 years ago.
My contact form on my web page finally send emails, but it doesn't send it in the proper format. This is the email of what I am getting. I've hidden the email and organization for privacy reasons.
From-- norgun
Subject-- Test Email: ***#gmail.com Message: Sbsbdb
Message--
MIME-Version: 1.0
Content-type: text/plain; charset=iso-8859-1
From: Test <***#gmail.com>
Reply-To: <***#gmail.com>
X-Mailer: PHP/7.0.21
Anyway, as you can see from the above, the name, email, and message content that the person would've written in the contact form are in the subject line instead of the actual email box. Is there a way that I could format my code so that the message and the name that they wrote down are in the message box instead of the subject box, and the email gets sent from the person who put their email in the form, not "norgun" which is what I came up with for the website?
Here is my code so far:
<?php
$to = 'index#indexmarkets.biz';
$name = !empty($_POST['name']) ? filter_var(trim($_POST['name']), FILTER_SANITIZE_STRING) : '';
$from = !empty($_POST['email']) ? filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL) : $to;
$message = !empty($_POST['message']) ? filter_var(trim($_POST['message']), FILTER_SANITIZE_STRING) : '';
$body = "Name: {$name}\r\nEmail: {$from}\r\nMessage: {$message}";
$body = wordwrap($body, 70, "\r\n");
$headers = [
'MIME-Version: 1.0',
'Content-type: text/plain; charset=iso-8859-1',
"From: $name <$from>",
"Reply-To: <$from>",
'X-Mailer: PHP/' .phpversion()
];
$success = mail($to, $body, implode("\r\n", $headers));
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
die(json_encode(['success' => $success]));
}
echo $success ? 'Sent Successfully.' : 'An error occurred';
ini_set('display_errors', 1); error_reporting(E_ALL);
That's because you're passing your variable $body as the subject parameter to the mail() function. This line:
$success = mail($to, $body, implode("\r\n", $headers));
Should instead be something like this:
$success = mail($to, $subject, $body, implode("\r\n", $headers));
Make sure you set $subject to something.

Changing CGI-Mailer in PHP mail script [duplicate]

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

sending mail from php when link in message body

i have a php script
<?php
$to = 'somebody#somedomain.com';
$subject = 'Test mail';
$message = 'mysitedomain.com';
$from = 'support#mysitedomain.com';
$headers = 'From:' . $from;
mail($to,$subject,$message,$headers);
echo 'Mail Sent.';
?>
When i run this code mail not send. If i change message to mysitedomaincom (without dot before com) the mail send succesfull.
Anybody have a solution for this?
This codes that tells the mailer and the recipient that the email contains well formed HTML that it will need to interpret
If you want you can change content of $message, now with this codes you can send HTML content mail.
<?PHP
$to = 'somebody#somedomain.com';
$subject = 'Test mail';
$headers = "From: Support <support#mysitedomain.com>" . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<h1>mysitedomain.com</h1>';
$message .= '</body></html>';
mail($to, $subject, $message, $headers);
?>

PHP send mail show name instead of an email [duplicate]

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>

Categories