I have the following php mail file :
<?php $name = $_POST['name'];
$email = $_POST['email'];
$choice = $_POST['choice'];$num = $_POST['num'];
$choice1 = $_POST['choice1'];$num1 = $_POST['num1'];
$phone= $_POST['phone'];
$town= $_POST['town'];
$formcontent="
Name: $name \n
Number: $phone \n
Choice: $choice Amount:$num
Choice: $choice1 Amount:$num1
Town: $town \n
Email: $email" ;
$recipient = "info#domain.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";?>
Can I add the $email to the recipients? I want to add the email entered in the form into the recipients that receive the email. (info#domain.com and the email entered in the form ($email = $_POST['email'];) will receive the email.
You can add multiple email addresses to $recipient by separating them with commas. Try this.
$recipient = "info#domain.com, $email";
Edit
Here is the whole thing.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$choice = $_POST['choice']; $num = $_POST['num'];
$choice1 = $_POST['choice1']; $num1 = $_POST['num1'];
$phone= $_POST['phone'];
$town= $_POST['town'];
$formcontent = "
Name: $name \n
Number: $phone \n
Choice: $choice Amount:$num
Choice: $choice1 Amount:$num1
Town: $town \n
Email: $email";
$recipient = "info#domain.com, $email";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank you";
?>
Related
I am trying to get the $subject = "Add my Fur Baby to Cape Breton Cares Contest"; to be the subject in the email as well. Would anyone know how I can do this. Thanks
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$uploaded_file = $_FILES['uploaded_file']['name'];
$formcontent=" First Name: $first_name \n Fur Babies Name: $last_name \n Email: $email \n Subject: $subject \n Image: $uploaded_file";
$recipient = "contest#capebretoncares.com";
$subject = "Add my Fur Baby to Cape Breton Cares Contest";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header("Location: https://www.capebretoncares.com/p/thank-you/");
?>
Here, use this code. $subject should be defined before $formcontent
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$recipient = "contest#capebretoncares.com";
$subject = "Add my Fur Baby to Cape Breton Cares Contest";
$uploaded_file = $_FILES['uploaded_file']['name'];
$formcontent=" First Name: ".$first_name." \n Fur Babies Name: ".$last_name." \n Email: ".$email." \n Subject: ".$subject." \n Image: ".$uploaded_file;
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header("Location: https://www.capebretoncares.com/p/thank-you/");
The reason this does not work right now is because the $subject variable is set after the $formcontent, just move $subject before $formcontent:
$subject = "Add my Fur Baby to Cape Breton Cares Contest";
$formcontent = "First Name: $first_name \n Fur Babies Name: $last_name \n Email:
$email \n Subject: $subject \n Image: $uploaded_file";
$recipient = "contest#capebretoncares.com";
I know there are similar people that posted contact form help but I have an issue with mine. Everything works but when I submit I get an e-mail from apache that shows a blank message. However, when I use my own e-mail address in the form input , it works.
Here is my code
<?php
if(isset($_POST['submit'])){}
$name = $_POST['name'];
$email = $_POST['email'];
$minrooms=$_POST['mrooms'];
$message = $_POST['comment'];
$formcontent="From: $name \n Email: $email \n Min Number of Rooms: $minrooms\n Message: $message ";
$recipient = "kellito13#gmail.com";
$subject = "Contact Form";
$mailHeader = "From: $email \r\n";
send_contact= mail($recipient, $subject, $formcontent, $mailHeader) or die("Error!");
echo "Thank You!";
}
else{
echo"Error";
}
?>
You have syntax errors in your code with {} and send_contact= mail($recipient, $subject, $formcontent, $mailHeader) or die("Error!");.
It should be something like this:
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$minrooms=$_POST['mrooms'];
$message = $_POST['comment'];
$formcontent="From: $name \n Email: $email \n Min Number of Rooms: $minrooms\n Message: $message ";
$recipient = "kellito13#gmail.com";
$subject = "Contact Form";
$mailHeader = "From: $email \r\n";
$send_contact= mail($recipient, $subject, $formcontent, $mailHeader) or die("Error!");
echo "Thank You!";
}
else{
echo"Error";
}
?>
<?php
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Number= $_POST['Number'];
$Message= $_POST['Message'];
$formcontent="
Name: $Name \n
Number: $Number \n
Email: $Email \n
Message: $Message";
$recipient = "info#domain.com";
$subject = "Contact Form";
$mailheader = "From: $Email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
The number is not displaying but name, email, message are displaying in formcontent. Empty space is showing in place of number while execution.
san.
Try echoing the value of $_POST['Number']. If it's still an empty string, then there must be a problem on the process of fetching the data via post method or in your HTML field for Number.
I've created a working contact form with a PHP file. I have read so many post about security, to the point I'm really confused about what code is needed to filter out potential spammers. Code below is what I have so far. Would you be so kind as to provide any code that would secure this php file so I can learn the correct way.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "";
$subject = "Contact Form Enquiry";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
$homepage = file_get_contents('http://www.fashionablefondants.co.uk/response.html');
echo $homepage;
?>
So I'm using this code for php mail and I keep getting MY email address rather than the actualy senders email, when I test it on my website's contact form. Any help? By the way, I use my email in the recipients address.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$call = $_POST['call'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Type: $type \n Message: $message";
$recipient = "myemail#address.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>
Have a look at php:mail manual in the example#3 you can see,
<?php
mail('nobody#example.com', 'the subject', 'the message', null,'-fwebmaster#example.com');
?>
You can see
The additional_parameters parameter can be used to pass an additional parameter to the program configured to use when sending mail using the sendmail_path.