I cannot get this form to send if I use anything other than $from = 'From: . $email';. If I change it to anything else, it will not send. When it does send with this information, it comes in from .$email#mbox.freehostia.com.
What I would prefer is have the from email address be the email that was submitted in the form, so the receiver can respond without having to create a new email. I've searched everything and can't find an answer to this specific issue.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$from = 'From: . $email';
$to = 'info#resourcedmichigan.com';
$subject = 'ResourcED Career Submission';
$body = "From: $name\nEmail: $email\nPhone Number: $phone\nMessage: $message";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
include("inc/header.php");
echo '<div class="container"><div class="spacer-top"><h3>Thank you for your interest in ResourcED! We will be in contact with you soon!</h3></div></div>';
include("inc/footer.php");
} else {
echo '<div class="container"><h3>Something went wrong. Go back and try again!</h3></div>';
}
}
?>
Variables will not be interpolated inside of single quotes and the concatenation operator is unnecessary.
$from = 'From: . $email';
should be
$from = "From: $email";
or
$from = 'From: ' . $email;
Related
I am trying to adjust my code to able to reply to sender email from PHP contact form. please check my code below to give advise. Thank you
<?php
$marke = $_POST['marke'];
$modell = $_POST['modell'];
$name = $_POST['name'];
$adresse = $_POST['adresse'];
$telefon = $_POST['telefon'];
$email = $_POST['email'];
$to = 'myemail#gmail.com';
$from = 'myemail#gmail.com';
$subject = 'Contact Form';
$body = "marke: $marke\n modell: $modell\n name: $name\n adresse: $adresse\n
email: $email\n telefon: $telefon\n";
?>
<?php
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
header("Location: http://www.website.com/sent.php");
} else {
echo '<p>Oops! An error occurred. Try sending your message again.</p>';
}
}
?>
First make headers
$headers = "From: $from\r\nReply-to: $email";
Than fix calling of mail function to be
mail ($to, $subject, $body, $headers)
Didn't tried it from times when it was PHP 4 but it will probably work as you expected...
Addition:
I just checked on php.net... go to this url http://php.net/manual/en/function.mail.php and check "Example #2 Sending mail with extra headers."
I created a web forum with the script below. I am able to receive inquiries from my site; however, the visitor's email address is not showing in the email sent from the webmaster. I would like to have some guidance here to fix the problem.
Here is my PHP script:
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "abc#gmail.com";
$subject = "Contact Form";
mail($recipient, $subject, $formcontent) or die("Error!");
echo "Thank You!";
?>
Here is what I got from the webmaster:
From: xx
Message: xx
No email address listed in the email sent by the webmaster.
I found some similar scripts on the web with two additional rows:
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
This actually gives me an Error output.
How can I fix the issue?
Thanks!
The third parameter of mail() is just the actual body of the message, which you have saved as $message. The fourth variable is where you define the headers, and is where you define who the message is From. Note that you don't actually need to pass the message as a header, and as such, your variable $formcontent, shouldn't contain your From: header. However, you do need to provide carriage returns in the form of "\r\n" after the provided email address.
The modified code would look like this:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent = "From: $name" . "\r\n";
$recipient = "abc#gmail.com";
$subject = "Contact Form";
mail($recipient, $subject, $message, $formcontent) or die("Error!");
echo "Thank You!";
?>
Hope this helps! :)
You could add headers to the mail function.
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "abc#gmail.com";
$subject = "Contact Form";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: <$email>" . "\r\n";
mail($recipient, $subject, $formcontent, $headers);
FYI - I would santize and validate all POST values before using them in this manner
So I am mailing the contents of a form to a client and he would like the person who sent the form to be Cc'd in.
I have done some research and it appears I need to use the header code to set the from, subject and cc but my code is set up differently - please see below:
<?php
$relatedproduct = $_POST['related-product'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Phone: $phone \n About: $relatedproduct \n Message: $message";
$recipient = "email#mydomain.com";
$subject = "More information regarding $relatedproduct";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header('Location: ' . $_SERVER['HTTP_REFERER']);
?>
Would it be possible to do it like this?
<?php
$relatedproduct = $_POST['related-product'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = $_POST['email'];
$subject = "More information regarding $relatedproduct";
$formcontent="From: $name \n Phone: $phone \n About: $relatedproduct \n Message: $message";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
// Mail it
mail($to, $subject, $formcontent, $headers);
?>
php.net/mail
Yes, as you have it:
...
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthday#example.com' . "\r\n";
mail($to, $subject, $content, $headers);
?>
Incidentally, please sanitise your POST variables before you inject them (e.g. $to = $_POST['email'];).
As #Rhopercy says in their comment, perhaps an email library will help you as it takes care of most things for you. Take a look at PHPMailer or SwiftMail.
Should be like this:
$relatedproduct = $_POST['related-product'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers = "From: $email\r\nReply-To: $email";
$headers .= 'Cc: test#test.com\r\n';
$headers .= 'Bcc: test#test.com\r\n';
$headers .= "Return-Path: <info#premierinspectiontn.com>\r\n";
$to = $_POST['email'];
$subject = "More information regarding $relatedproduct";
$formcontent="From: $name \n Phone: $phone \n About: $relatedproduct \n Message: $message";
// Mail it
mail($to, $subject, $formcontent, $headers);
Hello I am fairly new to PHP and do not know a lot at the moment. I have modified a contact form an have come into some problems regarding the mail going straight to junk.
I assume this is for the reason that (unknown sender) keeps displaying in the email header. I would appreciate it if someone could help me correct this. The following is the code that I have implemented into the website:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Wirral PT Enquiry';
$to = 'joebloggs#hotmail.com';
$subject = 'Wirral PT Enquiry';
$human = $_POST['human'];
$headers = "enquiry#wirralpt.co.uk";
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($human == '2') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p> 1+1=2!! </p>';
}
} else {
echo '<p>You need to fill everything!!</p>';
}
}
?>
$from = 'From: Wirral PT Enquiry'; should contain the 'from' email address, not just the name:
$from = 'From: Wirral PT Enquiry <enquiry#wirralpt.co.uk>';
Try that?
try using
$headers = "Reply To :enquiry#wirralpt.co.uk";
Might work for you
also,
$headers = "From :enquiry#wirralpt.co.uk";
try both of these with you relevant email IDs
Change your headers to this:
$headers = 'From: enquiry#wirralpt.co.uk' . "\r\n" .
'Reply-To: enquiry#wirralpt.co.uk' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
and your mail should look this this:
mail ($to, $subject, $body, $headers)
This error can also be caused if while using SMTP settings for PhpMailer, $mail->IsSMTP(); is missed
I am using a simple contact form and script on a website. The only issue I have is that I would like the email of the person filling out the form used as the reply to e-mail address rather than my servers address when I receive their submission. This is so I can simply reply to the contact rather than having to copy and paste their address and start a new reply to e-mail.
Any simple way to do this?
The below is the simple code I am using.
<?php
header('Location: http://XXXXXXXXXXXXXXXXX/contact.html');
$name = $_REQUEST['Person'];
$company = $_REQUEST['company'];
$address = $_REQUEST['address'];
$city = $_REQUEST['city'];
$state = $_REQUEST['state'];
$zip = $_REQUEST['zip'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$subject = $_REQUEST['subject'];
$details = $_REQUEST ['details'];
$byphone = $_REQUEST ['Phonebox'];
$emailbox = $_REQUEST['Emailbox'];
$message = "From $name\n Company $company\n Address $address\n $city $state $zip\n Email $email\n Phone $phone\n Subject $subject\n\n Details $details\n\n Contact by $byphone $emailbox";
mail ("XXXXXXXXX.com", "Customer Inquiry", "$message", "$email");
?>
Check this out: http://php.net/manual/en/function.mail.php
(Example below)
<?php
$to = 'server_owner#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: i_filled_the_form#example.com' . "\r\n" .
'Reply-To: i_filled_the_form#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>