PHP email - want to send to different emails - php

Currently:
I have the PHP form below, where users select one of the checkboxes a notification comes as to which location they are looking to book.
Goal:
I would like it to now be that when someone clicks Canterbury an email is sent to email1#gmail.com, when to Broadstairs - email2#gmail.com, and when to deal - email3#gmail.com
I have been going in circles trying to make the changes but I get in a mess.
FYI I don't mind changing the checkboxes into a dropdown, but I would rather keep it this way.
Current PHP section:
<?php
ini_set('display_errors',0);
error_reporting(E_ALL);
$error = '';
if(isset($_POST['send']))
{
$name = $_REQUEST['Name'];
$telephone = $_REQUEST['Telephone'];
$email = $_REQUEST['Email'];
$message = $_REQUEST['Message'];
$headers = "From: $email";
$subject = "Web Contact Data";
$selectedProjects = 'None';
if(isset($_POST['projects']) && is_array($_POST['projects']) && count($_POST['projects']) > 0){
$selectedProjects = implode(', ', $_POST['projects']);
}
$fields = array();
$fields["Name"] = $name;
$fields["Telephone"] = $telephone;
$fields["Email"] = $email;
$fields["Message"] = $message;
$fields["Location"] = $selectedProjects;
$to = "email4#gmail.com" ; // change all the following to $_POST
$body = "You have recieved the following information:\n\n";
foreach($fields as $key => $value)
{
$body .= sprintf("%20s: %s\n",$key,$value);
} // end foreach($fields as $key => $value)
$subject2 = "Thank you for contacting us.";
$autoreply = "<html><body><p>Dear " . $name . ",</p><p>Message goes here.</p></body></html>";
$headers2 = 'MIME-Version: 1.0' . "\r\n";
$headers2 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers2 .= 'From: email4#gmail.com' . "\r\n";
$send=false;
if($name == '')
{
$error = "You did not enter your name, please try again.";
selected_values();
}
$send=false;
if($telephone == '')
{
$error = "You did not enter your telephone number, please try again.";
selected_values();
}
elseif(!preg_match("/^[[:alnum:]][a-z0-9_.'+-]*#[a-z0-9-]+(\.[a-z0-9-]{2,})+$/", $email))
{
$error = "You did not enter a valid email address, please try again.";
selected_values();
}
else
{
$send = mail($to, $subject, $body, $headers);
$send2 = mail($email, $subject2, $autoreply, $headers2);
if(!isset($error) && !$send)
{
$error = "We have encountered an error sending your mail, please notify [email]email4#gmail.com[/email].";
}
else
{
unset($_REQUEST['Name']);
unset($_REQUEST['Email']);
unset($_REQUEST['Telephone']);
unset($_REQUEST['Message']);
}
} // end else
}// end of if(isset($_POST['send']))
?>
And the HTML form is this:
<form method="post" action="./lead.php">
<ul>
<li>
<?php
if(isset($error))
echo '<div class="register_error">'.$error.'</div>';
if(isset($send) && $send== true){
=echo '<div class="contact-send-green">Thank you for your message.</div>';
}
if(!isset($_POST['send']) || isset($error))
?>
</li>
<li>
<input type="checkbox" name="projects[]" value="Broadstairs">
<label for="type2">Broadstairs</label>
<br /><br />
<input type="checkbox" name="projects[]" value="Canterbury">
<label for="type2">Canterbury</label>
<br /><br />
<input type="checkbox" name="projects[]" value="Deal">
<label for="type2">Deal</label>
</li>
<li>
<textarea name="Message" rows="5" cols="29"><?php if(isset($_REQUEST['Message'])) echo $_REQUEST['Message']; ?></textarea>
</li>
<li>
<input type="submit" name="send" value="Send Message" id="send-email">
</li>
</ul>

For single selection a simple switch(){} would do the magic.
switch($_POST['projects']){
case "Broadstairs":
$to = "email#email.com";
break;
case "Canterbury":
$to = "email#email.com";
break;
case "Deal":
$to = "email#email.com";
break;
}
And then remove the [] from the input names as you won't need them to be a array. (As such:)
<input type="checkbox" name="projects" value="Broadstairs">
And then perhaps considering using some JS/jQuery to check that only 1 is selected at a time?

There are 3 issues with the script you have provided
You want to select only a single email address however, you are using the name projects[] as the checkbox names - this will create an array, however since HTML5; if you use a name multiple times even without the [] it will create an array.
Given the above, you should most definitely as you mentioned change to a <select> box, or alternatively <radio> buttons.
You should not use $_REQUEST unless absolutely needed, you are providing an easy oppurtunity for sql injection.
Here is an example of how I would do it.
HTML
<form method="post" action="./lead.php">
<ul>
<li>
<?php
if(isset($error)) echo '<div class="register_error">'.$error.'</div>';
if(isset($send) && $send== true) echo '<div class="contact-send-green">Thank you for your message.</div>';
?>
</li>
<li>
<label for="Broadstairs"><input type="radio" name="projects" id='Broadstairs' value="Broadstairs"> Broadstairs</label>
<label for="Canterbury"><input type="radio" name="projects" id='Canterbury' value="Canterbury">Canterbury</label>
<label for="Deal"><input type="radio" name="projects" id='Deal' value="Deal">Deal</label>
</li>
<li>
<textarea name="Message" rows="5" cols="29"><?=(strlen($_POST['Message'])>0) ? $_POST['Message'] : ''; ?></textarea>
</li>
<li>
<button type='submit'>Send Message</button>
</li>
</ul>
And your PHP
<?php
if (!empty($_POST)) {
// Dispatch message to selected office
$name = $_POST['Name'];
$telephone = $_POST['Telephone'];
$email = $_POST['Email'];
$message = $_POST['Message'];
$subject = "Web Contact Data";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: My website <my-email#example.com>' . "\r\n";
if ($_POST['projects'] == 'Canterbury') $to = "example#gmail.com" ;
elseif ($_POST['projects'] == 'Broadstairs') $to = "example#gmail.com" ;
else $to = "example#gmail.com" ;
mail($to, $subject, $message, $headers);
// Dispatch "Thank You" email
$subject = "Your message has been received!";
ob_start();
?>
<html>
<body>
<p>Dear <?=$name?></p>
<p>Thank you for contacting us,</p>
<p>We have received your message and will respond to you as soon as possible.</p>
<p>This is an automatic response to your inquiry and it is not necessary to reply.</p>
<p>Thank you,</p>
</body>
</html>
<?
$message = ob_get_flush();
mail($email, $subject, $message, $headers)
}
?>
I would recommend Google Recaptcha too.
Hope this helps

You need to add if, elseif, and else condition to your code.
Replace $to = "email1#email.com" ; with following code
if($_POST['projects'] == 'Broadstairs')
{
$to = "email2#email.com";
}
else if($_POST['projects'] == 'Canterbury')
{
$to = "email3#email.com";
}
else if($_POST['projects'] == 'Deal')
{
$to = "email4#email.com";
}
else
{
$to = "email5#email.com";
}

Related

Contact Form Send a copy to user/sender

I have a website template with a contact form and sendmail.php file. What I want to do is give the sender the option to send a copy of the form to themselves.
I've tried different suggestions which I've found online but without success.
I've managed to get the checkbox option in the html file pretty easily, but even if it's selected, the sender doesn't get a copy of the email. So my thinking is that there's something on the PHP end that I'm missing or have down incorrectly.
I tried:
//cc option
$headers["From"] = "$clientEmail";
$headers["To"] = "$emailTo";
$headers["Subject"] = $subject;
$headers['Cc'] = '$clientEmail';
but that didn't work.
Here is the HTML and PHP code:
HTML:
<div class="contact-us container">
<div class="row">
<div class="contact-form span7">
<p>Want to get in touch? Use the form below to send an email.</p>
<form method="post" action="assets/sendmail.php">
<label for="name" class="nameLabel">Name</label>
<input id="name" type="text" name="name" placeholder="Enter your name...">
<label for="email" class="emailLabel">Email</label>
<input id="email" type="text" name="email" placeholder="Enter your email...">
<label for="subject">Subject</label>
<input id="subject" type="text" name="subject" placeholder="Your subject...">
<label for="message" class="messageLabel">Message</label>
<textarea id="message" name="message" placeholder="Your message..."></textarea>
<button id="button">Send</button>
</form>
<input type="checkbox" value="1" id="sendCopy" name="sendCopy" class="rsp-cB"/>
<label for="sendCopy">Send me a copy.</label>
</div>
</div>
</div>
PHP:
// Email address verification
if($_POST) {
// Enter the email where you want to receive the message
$emailTo = 'email#gmail.com';
$clientName = trim($_POST['name']);
$clientEmail = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
$array = array();
$array['nameMessage'] = '';
$array['emailMessage'] = '';
$array['messageMessage'] = '';
if($clientName == '') {
$array['nameMessage'] = 'Please enter your name.';
}
if(!isEmail($clientEmail)) {
$array['emailMessage'] = 'Please insert a valid email address.';
}
if($message == '') {
$array['messageMessage'] = 'Please enter your message.';
}
if($clientName != '' && isEmail($clientEmail) && $message != '') {
// Send email
$headers = "From: " . $clientName . " <" . $clientEmail . ">" . "\r\n" . "Reply-To: " . $clientEmail;
mail($emailTo, $subject, $message, $headers);
}
header('Location: thanks.php');
}?>
I'm a complete newbie so please suggest, in layperson terms, what is required and in which files and where.
P.S. I know there are other similar questions on here, but I've tried them as well as googling for other suggestions and I haven't been able to get it to work.
You cant use headers as array like this
// Cc option
$headers["From"] = "$clientEmail";
$headers["To"] = "$emailTo";
$headers["Subject"] = $subject;
$headers['Cc'] = "$clientEmail";
Correct way is.
$to = 'reciver_address#gmail.com'; // Recipient of email
$subject = 'I\'m sending a mail'; // Subject of email
$message = 'This is message'; // Body of email
$header = 'From: address#gmail.com'; // Sender email address
$header .= "\r\n" . 'Cc: copy#gmail.com'; // Copy of email
Then in mail()
mail($to, $subject, $message, $header);
Try this header.
$headers = "From: " . $clientName . " <" . $clientEmail . ">" . "\r\n";
$headers .= "Reply-To: " . $clientEmail. "\r\n";
$headers .= "Cc: " . $clientEmail. "\r\n";
You are right, there is the PHP Part missing. If you use the BuildIN PHP Mail function you have to add the CC to the headers.
Not tested, but add this to your code below the first "$header" and it should send an copy to the Client:
// add CC when checked in Form and attach to headers
if ($_POST['sendCopy'] == '1') {
$headers .= "Cc: $clientEmail" . "\r\n";
}
I would recommend to have a look at some better Mail Solutions like: PHPMailer
please try this(ignore code before)
<?php
if($_SERVER['REQUEST_METHOD']=="POST") {
if($_POST['sendCopy']=="1") {
// Enter the email where you want to receive the message
$emailTo = 'email#gmail.com';
$clientName = trim($_POST['name']);
$clientEmail = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
$array = array();
$array['nameMessage'] = '';
$array['emailMessage'] = '';
$array['messageMessage'] = '';
if($clientName == '') {
$array['nameMessage'] = 'Please enter your name.';
}
if(!isEmail($clientEmail)) {
$array['emailMessage'] = 'Please insert a valid email address.';
}
if($message == '') {
$array['messageMessage'] = 'Please enter your message.';
}
if($clientName != '' && isEmail($clientEmail) && $message != '') {
// Send email
$headers = "From: " . $clientName . " <" . $clientEmail . ">" . "\r\n" . "Reply-To: " . $clientEmail;
mail($emailTo, $subject, $message, $headers);
}
header('Location: thanks.php');
}
}
?>

Contact form with html and php

Hi im a newbie so i tried to use some source code to create a contact form for my website it does not work so i need help here is my code:
HTML
<div class="col-md-6 col-sm-6">
<div class="row contact-form">
<form id="contact-form" action="php/mail.php">
<fieldset class="col-md-6 col-sm-6">
<input id="name" type="text" name="name" placeholder="Name">
</fieldset>
<fieldset class="col-md-6 col-sm-6">
<input type="email" name="email" id="email" placeholder="Email">
</fieldset>
<fieldset class="col-md-12">
<input type="text" name="subject" id="subject" placeholder="Subject">
</fieldset>
<fieldset class="col-md-12">
<textarea name="comments" id="comments" placeholder="Message"></textarea>
</fieldset>
<fieldset class="col-md-12">
<input type="submit" name="send" value="Send Message" id="submit" class="button">
</fieldset>
</form>
</div> <!-- /.contact-form -->
</div> <!-- /.col-md-6 -->
PHP
<?php
include 'functions.php';
if (!empty($_POST)){
$data['success'] = true;
$_POST = multiDimensionalArrayMap('cleanEvilTags', $_POST);
$_POST = multiDimensionalArrayMap('cleanData', $_POST);
// your email adress
$emailTo ="brinny#abvconstruction.co.za"; // "yourmail#yoursite.com";
// from email adress
$emailFrom ="contact#yoursite.com"; // "contact#yoursite.com";
// email subject
$emailSubject = "Mail from Web Contact Form ";
$name = $_POST["name"];
$email = $_POST["email"];
$comment = $_POST["comment"];
if($name == "")
$data['success'] = false;
if (!preg_match("/^[_\.0-9a-zA-Z-]+#([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email))
$data['success'] = false;
if($comment == "")
$data['success'] = false;
if($data['success'] == true){
$message = "NAME: $name<br>
EMAIL: $email<br>
COMMENT: $comment";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html; charset=utf-8" . "\r\n";
$headers .= "From: <$emailFrom>" . "\r\n";
mail($emailTo, $emailSubject, $message, $headers);
$data['success'] = true;
echo json_encode($data);
}
}
Thank you. I changed the code to this :
<?php
include 'functions.php';
if (!empty($_POST)){
$data['success'] = true;
//your email adress
$emailTo ="brinny#abvconstruction.co.za"; //"yourmail#yoursite.com";
//from email adress
$emailFrom = $_POST["email"]; //"contact#yoursite.com";
//email subject
$emailSubject = $_POST["subject"];
$name = $_POST["name"];
$email = $_POST["email"];
$comments = $_POST["comments"];
if($name == "")
$data['success'] = false;
if (!preg_match("/^[_\.0-9a-zA-Z-]+#([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email))
$data['success'] = false;
if($comments == "")
$data['success'] = false;
if($data['success'] == true){
$message = "NAME: $name<br>
EMAIL: $email<br>
COMMENT: $comments";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html; charset=utf-8" . "\r\n";
$headers .= "From: <$emailFrom>" . "\r\n";
mail($emailTo, $emailSubject, $message, $headers);
$data['success'] = true;
echo json_encode($data);
}`enter code here`
}
I would also like to know if i should use a php_redirect to get the browser to open the html file not the php file
The website is abvconstruction.co.za. If any one can check what is the error on my code
First, you have to add method="post" to your <form>, otherwise it's sending the data with GET.
Also remove these lines, which clear the POST data:
$_POST = multiDimensionalArrayMap('cleanEvilTags', $_POST);
$_POST = multiDimensionalArrayMap('cleanData', $_POST);
first remove these line, they clear the post values
$_POST = multiDimensionalArrayMap('cleanEvilTags', $_POST);
$_POST = multiDimensionalArrayMap('cleanData', $_POST);

Form not sending email

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.

Why is this contact form not working?

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

HTML/PHP form not sending email

I have a form which does everything right except send the input values to my email, what am I doing wrong? Ps: not using local server, so that's not it.
EDIT: I'm not getting any email whatsoever.
Tried changing the if(isset($_POST['enviar'])) { part but still not working.
Tried the chatty echos. the only if statement that isn't behaving properly is stripslashes. It stops at the else statement.
The form snippet:
<div id="contact-wrapper">
<?php if(isset($hasError)) { //If errors are found ?>
<p class="error">Please check if you entered valid information.</p>
<?php } ?>
<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
<p><strong>Email sent with success!</strong></p>
<p>Thank you for using our contact form <strong><?php echo $name;?></strong>, we will contact you soon.</p>
<?php } ?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform">
<div>
<label for="name"><strong>Name:</strong></label>
<input type="text" size="50" name="contactname" id="contactname" value="" class="required" />
</div>
<div>
<label for="email"><strong>E-mail:</strong></label>
<input type="text" size="50" name="email" id="email" value="" class="required email" />
</div>
<div>
<label for="subject"><strong>Subject:</strong></label>
<input type="text" size="50" name="subject" id="subject" value="" class="required" />
</div>
<div>
<label for="message"><strong>Message:</strong></label>
<textarea rows="5" cols="50" name="message" id="message" class="required"></textarea>
</div>
<input type="submit" value="enviar" name="submit" id="submit" />
</form>
</div>
and the PHP:
<?php
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure that the subject field is not empty
if(trim($_POST['subject']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['subject']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+#[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'myemail#email.com'; //Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>
The ereg() family of functions are deprecated. use the preg_...() equivalents instead. They work almost exactly the same, except requiring delimiters around the match patterns.
As well, don't use PHP_SELF in your form. That value is raw user-supplied data and can be trivially subverted for an XSS attack.
Checking for a particular form field to see if a POST occured is somewhat unreliable - you might change the field's name later on and your check will fail. However, this
if ($_SERVER['REQUEST_METHOD'] == 'POST) { ... }
will always work, no matter how many or few fields are in the form, as long as the form was actually POSTed.
As for the actual problem, I'm assuming the mail is getting sent out, or you'd have complained about that. That means your variables aren't being populated properly. Instead of just sending the mail, echo out the various variables as they're built, something like:
echo 'Checking name';
if ($_POST['name'] .....) {
echo 'name is blank';
} else {
$name = ...;
echo "Found name=$name";
}
Basically have your code become extremely "chatty" and tell you what it's doing at each stage.
#dafz: Change
if(isset($_POST['submit'])) {
to
if(isset($_POST['enviar'])) {
#Marc B deserves another up-vote for his answer as well.
Edit
You can try the following update.
if(!isset($hasError)) {
$siteAddress = 'validaddress#yourdomain.com'; //Put admin# or info# your domain here
$emailTo = 'myemail#email.com'; //Put your own email address here
$body = "Name: $name \r\nEmail: $email \r\nSubject: $subject \r\nComments: $comments \r\n";
$headers = 'To: ' . $name . ' <' . $emailTo . '>' . "\r\n";
$headers .= 'From: My Site <' . $siteAddress . '>' . "\r\n";
$headers .= 'Reply-To: ' . $email . "\r\n";
if (mail($emailTo, $subject, $body, $headers)) {
$emailSent = true;
} else {
$emailSent = false;
}
}

Categories