It seems everything is in place:
PHP:
<?php
if (!empty($_POST['name'])){
$msg = "name". $_POST['name'];
}else{
$fname = NULL;
echo "Name Required.<br />";
}
if (!empty($_POST['email'])){
$msg = "email". $_POST['email'];
}else{
$lname = NULL;
echo "Email Required.<br />";
}
if (!empty($_POST['www'])){
$msg = "Website". $_POST['www'];
}else{
$lname = NULL;
echo "Website Required.<br />";
}
if (!empty($_POST['comment'])){
$msg = "Comment". $_POST['comment'];
}else{
$email = NULL;
echo "A comment is required.<br />";
}
$recipient = "myemail#gmail.com";
$subject = "Form Feedback";
$mailheaders = "Reply-to". $_POST['email'];
//send the mail
mail($recipient, $subject, $msg, $mailheaders);
?>
HTML:
<div id="contact" style="height:280px; margin:1px 0;">
<form id="contactLP" method="post" action="inc/php/contact_validate.php">
<div class="align"><input type="text" name="name" tabindex="1" /></div>
<div class="align"><input type="text" name="email" tabindex="2" /></div>
<div class="align"><input type="text" name="www" tabindex="3" /></div>
<div class="align"><textarea id="txta" name="comment" cols="15" rows="5" tabindex="4"></textarea></div>
<span style="color:transparent;">test</span>
<br><br>
<div class="align"><input type="submit" class="submit" name="sendForm" id="SubmitContact" value="" tabindex="5" /></div>
</form>
</div><!--CONTACT-->
When I fill it out correctly and submit, it says "Thanks for your message" or something similiar, but then I get nothing in email.
I tried running this both on a server on the internet, along with on my local server running on my workstation.
Am I doing something wrong above???????
Yes, you are "name; $_POST['name'] "; should be "name". $_POST['name']; in every instance you use that string.
Your $msg is only holding the current value.
Try something like this for all your value assignment to $msg variable
$msg .= "Comment". $_POST['comment'];
mail function
You seem to have screwed up the $mailheaders variable slightly (reply-to section), try this code in a stand alone script. If even it fails, you may have to check your mail function and how it is set up on the server. (change the email addresses obviously)
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com';
mail($to, $subject, $message, $headers);
Related
I receive an email but it will read from unknown. Everything else seems to work. Here is a link to the page link I don't know much about php.
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mailTo = "contact#podmtg.com";
$headers = "From: ".$mailFrom;
$txt = "You have recieved an email from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: contact.html?mailsend");
}
?>
<form action="contactform.php" method="post" onsubmit="return confirm('Are you sure you want to submit this form?');">
<input type="text" name="name" placeholder="Name" required="required">
<input type="text" name="email" placeholder="Email" required="required">
<textarea name="message" placeholder="Write message here..." required="required"></textarea>
<button type="submit" name="submit">SUBMIT</button>
</form>
In this you have mention this `$headers = "From: ".$mailFrom; but not $mailFrom found. Use $email in place of $mailFrom.
I changed the code. You guys were right. Thank you!
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$message = $_POST['message'];
$mailTo = "contact#podmtg.com";
$headers = "From: ".$mailFrom;
$txt = "You have recieved an email from ".$name.".\n\n".$message;
mail($mailTo, $headers, $txt);
header("Location: index.html?mailsend");
}
?>
Im trying to create a contact form using php,and having some troubles.
the condition: isset($_POST['submit']) always produces false, even if I just submit a blank page.
here is my code:
contact.html part:
<form action='emailto.php' method='POST' enctype='text/plain'>
First Name:<br>
<input type='text' name='firstname'><br>
Last Name:<br>
<input type='text' name='lastname'><br>
Email Address:<br>
<input type='text' name='emailadd' ><br>
Subject:<br>
<input type='text' name='subject' ><br>
Message:<br>
<textarea name='message' rows=5 cols=30 ></textarea><br><br>
<input type='submit' value='Send' name='submit'>
</form>
emailto.php:
<?php
if (isset($_POST['submit'])) {
$to = "emailaddress";
$subject = $_POST['subject'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$Emailadd = $_POST['emailadd'];
$Message = $_POST['message'];
$Body= "";
$Body .= $firstname;
$Body .= $lastname;
$Body .= "\n";
$Body .= $Emailadd;
$Body .= "\n";
$Body .= $Message;
mail($to,$subject,$Body);
echo "Mail Sent! <a href='contact.html'>Go Back</a>";
} else {
header("Location: contact.html");
exit(0);
}
?>
Besides, what's weird is that if I delete the if-else statement in emailto.php,
after submitting, an error message will occur: undifined index: subject, firstname, lastname, emailadd, message...
I was totally confused..
Looking forward to hear some advice.
Thanks in advance.
Remove this enctype='text/plain' from your form and it will start working; I guarantee it. And if it fails, then you need to find out why that is and making sure that mail is available for you to use.
Sidenote: You should also check if any of the inputs are empty (and required which helps).
http://php.net/manual/en/function.empty.php
and use proper (full) headers for mail():
http://php.net/manual/en/function.mail.php
Otherwise, your mailout may be treated as spam or rejected altogether.
There should be a valid From: <email> as part of mail's 4th argument.
I.e. and from the manual:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
"Besides, what's weird is that if I delete the if-else statement in emailto.php, after submitting, an error message will occur: undifined index: subject, firstname, lastname, emailadd, message..."
Again; this is caused by enctype='text/plain' in the form which isn't a valid enctype for using the POST array.
Edit:
Add an if/else to mail(). If it echos "Houston we have a problem", then there's a problem on your end.
If it echo "Mail Sent!" but no mail is received, then look at your spam box. Mail has done its job and you need to find out why it was never sent/received.
<?php
if (isset($_POST['submit'])) {
$to = "emailaddress";
$subject = $_POST['subject'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$Emailadd = $_POST['emailadd'];
$Message = $_POST['message'];
$Body= "";
$Body .= $firstname;
$Body .= $lastname;
$Body .= "\n";
$Body .= $Emailadd;
$Body .= "\n";
$Body .= $Message;
if(mail($to,$subject,$Body)){
echo "Mail Sent! <a href='contact.html'>Go Back</a>";
} else { echo "Houston, we have a problem"; }
} else {
header("Location: contact.html");
exit(0);
}
?>
I've tried every php contact form tutorial but I can't get any of them to send the email properly. They all just show the code but don't send the email. This is the HTML code I have right now:
<form method="POST" action="scripts/contact.php">
<input id="name" name="name" placeholder="Name*" type="text" /> <br>
<input id="subject" name="subject" placeholder="Subject" type="text" /> <br>
<input id="email_address" name="email" placeholder="Email address*" type="text" /> <br>
<textarea id="message" name="message" placeholder="Your message*"></textarea>
<input id="submit" type="submit" name="submit" value="Send" />
</form>
and this is the php I have:
<?php
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "benmuschol#gmail.com";
$subject = "Hello World";
$message = "Name: $name \n Subject: $subject \n Email: $email \n Message: $message \n";
$headers = "From: $email" . $email;
mail($name,$email,$subject,$message,$headers);
echo "Mail Sent.";
?>
I have decent knowledge of HTMl but next to none of PHP. Any help would be greatly appreciated.
first you be sure that php file is exist in path scripts/contact.php
second look at phpinfo or php.ini for find is smptp server was setting or not
use following php code:
<?php
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "benmuschol#gmail.com";
$subject = "Hello World";
$message = "Name: $name \n Subject: $subject \n Email: $email \n Message: $message \n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: '.$email. "\r\n";
if(mail($to, $subject, $message, $headers))
{
echo "Mail Sent Successfully.";
}
else
{
echo "Error in Mail Sent.";
}
?>
I am having trouble sending the information from my PHP form to the email address. I am fairly new to PHP. Code is below:
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$myEmail = "shivambh28#gmail.com";
if (empty($name) || empty($subject) || empty($message)) {
$error = 'Please make sure to double check the fields for errors.';
} elseif (!filter_var($email1, FILTER_VALIDATE_EMAIL)) {
$error = 'Email is incorrect';
} else {
$headers .= "From: $email\r\n";
$headers .= "Reply-To: $myEmail\r\n";
$headers .= "Return-Path: $myEmail\r\n";
$headers .= "CC: $email\r\n";
$headers .= "BCC: $myEmail\r\n";
if ( mail($to,$subject,$message,$headers) ) {
$to = $myEmail;
$subject = $subject;
$message = $message;
$from = $email;
$headers = "From:" . $from;
echo "Mail Sent.";
} else {
echo 'failure to send email';
}
}
}
HTML:
<form id="contactForm" class="form-horizontal" action="<?php echo get_option('home'); ?>/email/" method="POST">
<input id="name" name="name" placeholder="Full Name" type="text">
<input id="subject" name="subject" placeholder="Subject" type="text">
<input id="email" name="email" placeholder="Email Address" type="email">
<textarea placeholder="Your Message" id="message" name="message" rows="10"></textarea>
<input type="submit" value="SEND" class="btn btn-primary btn-block">
</form>
NOTE: I am using WP CMS.
Your form is missing the method attribute. edit the code so that your form has method POST.
<form id="contactForm" class="form-horizontal" action="contact.tpl.php" method="POST">
secondly remove one of your mail function calls. if not your email will be sent twice
Form method POST is missing in the form tag.
<form id="contactForm" class="form-horizontal" action="contact.tpl.php" method="post">
You have wrong parameter $to in mail()
Try
....
....
//// use $email here not $to which is not initialised yet
if ( mail($email,$subject,$message,$headers) ) {
is place of
if ( mail($to,$subject,$message,$headers) ) {
Change your code.It was sending mail by 2times
$to = $myEmail;
$subject = $subject;
$message = $message;
$from = $email;
$headers = "From:" . $from;
if ( mail($to,$subject,$message,$headers) ) {
echo "Mail Sent.";
} else {
echo 'failure to send email';
}
And your form method is like POST
<form id="contactForm" class="form-horizontal" action="contact.php" method="post">
And main thing your file name is either contact.php or contact.tpl NOT contact.tpl.php
$to = $myEmail;
$subject = $subject;
$message = $message;
$from = $email;
$headers = "From:" . $from;
if(#mail($to, $subject, $message, $headers)) {
echo "Mail Sent";
} else {
echo "Fail";
}
There's a . (period) missing from the first $headers variable declaration. Might help.
It's my first time trying to make a contactform. And I've got a few problems
It's works, I get the email, but I don't get the name the name field with me in the email.
HTML:
<form method="post" name="contactform" action="scripts/contact.php">
<h3>Name</h3>
<input type="text" name="name">
<h3>Email Address</h3>
<input type="text" name="email">
<h3>Message</h3>
<textarea name="message"></textarea>
<br/><input class="submit" type="submit" value="Send Form">
</form>
PHP:
<?php
$to = "name#domane.com";
$subject = "Contact Us";
$name = $_POST['name'];
$email = $_POST['email'] ;
$message = $_POST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $name, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "One of the field are not filled as requirred"; }
?>
$name is my problem. I've I have it in, the email comes from hostmaster#domane.com, If I delete it, everything works fine. But I wan't the name to be sent to me. How?
Or should I do it completely different?
Also, if you leave all the fields blank, the "user" doesn't get any error message, and a blank email is sent to me.
Hope you can help me. :)
Michael Berkowski is correct. What you'll need to do is add the name to your message's body (not in the sense of the input name= attribute, rather the body of the email).
Something like this:
<?php
$to = "name#domane.com";
$subject = "Contact Us";
$name = $_POST['name'];
$email = $_POST['email'] ;
$message = $_POST['message'] ;
$headers = "From: $email";
$body = "Name: $name\r\n";
$body .= "Message: $message";
$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "One of the field are not filled as requirred"; }
?>
Revised:
HTML:
<form method="post" name="contactform" action="scripts/contact.php">
<label for="name">Name</label>
<input type="text" name="name" id="name" />
<label for="email">Email Address</label>
<input type="text" name="email" id="email" />
<label for="message">Message</label>
<textarea name="message" id="message"></textarea>
<br/><input class="submit" type="submit" value="Send Form" />
</form>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'] ;
$message = $_POST['message'] ;
$body = "Name: $name\r\n";
$body .= "Message: $message";
$to = "name#domane.com";
$from = "automailer#mydomainname.com (Website Automailer)";
$subject = "Contact Us";
$headers = "From: $from\r\n" .
"Reply-To: $email ($name)";
$sent = mail($to, $subject, $body, $headers) ;
if($sent) { echo "Your mail was sent successfully"; }
else { echo "One of the field are not filled as requirred"; }
?>
You should read the mail function documentation on php.net.
Have a look at the function signature:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
Now you're placing $name as the "$additional_headers" argument. You should pass $name and any extra relevant data in a $message argument instead.
Having that said, here's the correct code to send a message:
$sent = mail($to, $subject, "A message from $name: $message", $headers);
You should read more about how email messages are constructed. Instead of just putting a user defined message in there you probably want to specify some email headers, containing a more beautiful FROM: and the like...