How to send same PHP filled form to client also?
Like the below code sent the file to website owner in HTML/PHP forms
$to = "owner#gmail.com";
Now how to add client also here like
$to = "owner#gmail.com,$email";
Or what?
Use this
$field_email = "sender#mail.com"
$to = "owner#site.com, $feild_email ";
$subject = "Subject"
$message = "MESSAGE";
mail($to,$subject,$message);
Related
I am working on a contact us form, which sends an email to an email ID.
Following is the php script :
<?php
$name = $_POST['name'];
$phone = $_POST['phone'];
$visitor_email = $_POST['email'];
$email_from = "xxx#yyy.co.in";
$email_subject = "New form submission";
$email_body = "You have received a new message from the user $name";
$to = "xxx#yyy.co.in";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
$flag = mail($to,$email_subject,$email_body,$headers);
echo $flag;
?>
When I click Submit button I send a POST call to the page containing above script.
I receive form data correctly on that php page, but the email is not sent to the concerned email ID. The php mail() function returns false.
What may be the problem? Do I need to configure anything in the php.ini file?
I am working on Linux Mint and using LAMP.
I was working on a form and i had to use php to send the data through email. I am really new to coding. I just started working with php. My form works i even receive emails through it but the php page shows up blank. I tried using echo and error reporting but nothing shows up no html code shows up either. Its probably a newbie mistake. My php code:
<?php
$name = $_POST['fullName'];
$email_address = $_POST['email'];
$phone = $_POST['phoneNumber'];
$gender = $_POST['gender'];
$country = $_POST['country'];
$age = $_POST['age'];
$headers = "From: noreply#domainname.com";
$to = 'someone#example.com';
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\ngender: $gender\n\ncountry: $country\n\nage: $age";
mail($to,$email_subject,$email_body,$headers);
return true;
echo "thank you"
?>
You have two options right now:
Remove the return true;
Move the echo "thank you"; before your return true;
You can read more about return here:
http://php.net/manual/en/function.return.php
Side-note: you forgot a semi-colon (;) after your echo:
echo "thank you";
//--------------^
I have a relatively basic email form put together which I intend to email to a recipient using mail mime. This approach has worked for me in the past when the form was displayed on its own page i.e. a contact page.
Here I am using jquery to display a hidden div which contains my form from the home page. The problem is that although my validations pass the email is not being sent. I am at a loss for why and hope someone here can help me out!
The relevant php is as follows:
$path = get_include_path() . PATH_SEPARATOR . '/home/host/php';
set_include_path($path);
include('Mail.php');
include('Mail/mime.php');
$recipient_email = 'somebody#somewhere.com';
//validations are here
//send the email
$name = $_POST['name'];
$visitor_email = $_POST['from'];
$subject = $_POST['subject'];
$user_message = $_POST['message'];
$to = $recipient_email;
$from = $visitor_email;
$text = "From: $name \n Subject: $subject \n Message $user_message";
$message = new Mail_mime();
$message->setTXTBody($text);
$body = $message->get();
$extraheaders = array("From"=>$name, "To"=>$recipient_email, "Subject"=>$subject, "Reply-To"=>$visitor_email);
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send($to, $headers, $body);
echo "Success";
The jquery to display the form looks like this:
jQuery.fn.fadeToggle = function(speed, easing, callback) {
return this.animate({opacity: 'toggle'}, speed, easing, callback);
};
$(document).ready(function() {
$('#tellfriend').hide();
$('li a.email, #tellfriend a.close').click(function() {
$("#tellfriend").fadeToggle('slow');
});
});
One of my thoughts (and I'll experiment with it) is that because when the link is clicked to display form, the link is appended to the URL and so it may affect my form action? Not sure.. Any help is appreciated!
I was able to solve my problem by following a previous question I eventually found on Stack Overflow HERE
It turns out that I had to specify an outgoing mail server in order to send the form out. Still, it is odd that I have had it working in the past where I didn't need to follow such steps.
I'm using BlueHost and I can't seem to get my email form to work. This is the PHP:
$to = "test#email.com";
$subject = "test";
$message = "test message";
$from = $_POST['cf_email'];
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo $headers;
This doesn't seem to send the email. However, if I add ANY string in front of the email, then it works. e.g.:
$from = "zz".$_POST['cf_email'];
Can anyone tell me what I'm doing wrong? Thanks.
You cannot use any personal email ($_POST['cf_email']) in the 'From' header.
Also you have to add 'reply-to'.
Please check below thread for more info.
problem with php mail 'From' header
I have a single page portfolio website that I'm building and I have a contact form that I need to process using php send script. I'm a novice when it comes to PHP so I'm having trouble getting this to work. I've done some searching but I can't find what I'm looking for.
Here's what I have done, I copied this from a PHP contact page that I had built but the PHP and form are on the same page and I need an external send.php to process my form.
<?php
$error = ''; // error message
$name = ''; // sender's name
$email = ''; // sender's email address
$company = ''; // company name
$subject = ''; // subject
$comment = ''; // the message itself
if(isset($_POST['send']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];
$subject = $_POST['subject'];
$comment = $_POST['comment'];
if($error == '')
{
if(get_magic_quotes_gpc())
{
$message = stripslashes($message);
}
// the email will be sent here
// make sure to change this to be your e-mail
$to = "example#email.com";
// the email subject
// '[Contact Form] :' will appear automatically in the subject.
// You can change it as you want
$subject = '[Contact Form] : ' . $subject;
// the mail message ( add any additional information if you want )
$msg = "From : $name \r\ne-Mail : $email \r\nCompany : $company \r\nSubject : $subject \r\n\n" . "Message : \r\n$message";
mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
}
}
if(!isset($_POST['send']) || $error != '')
{
header("location: http://www.#.com/#contact");
}
?>
So for my form I want to have:
<form method="post" action="send.php" class="form">
I plan on using HTML5 and jQuery to validate the form, so I really only need the script to capture the info and send the email to a single address. After it sends I want the script to redirect back to the Contact page.
Edit:
I found a solution after spending a while on google.
http://www.website.com/#contact");
?>
For one thing, you haven't initialized the value for $message
$message = stripslashes($message);
You probably meant to use $comment instead of $message
Not sure what problem you're facing. Simply copy the PHP you have into a file called send.php and my first glance says it'll work if you change $message back to $comment and add error checking. If you still have issues, post back with more details.