Domanda

I've been trying to set up a contact form to send info to my email. I've checked the code and there's no syntax error or anything but I'm not receiving any test email. Can you please help me out?

Here's the HTML:

    <!--Start of Contact Form-->
    <div class="large-7 medium-10 small-12 medium-centered large-centered column">
        <div class="row">
            <form method="post" action="email2.php">

                    <input type="text" name="name" class="defaultText" title="your name">
                    <input type="text" name="email" class="defaultText" title="your email address">


                    <textarea name="comments1" class="defaultText" title="Tell us about your business"></textarea>
                    <textarea name="comments2" class="defaultText" title="How can we help?"></textarea>


               <div class="large-7 medium-10 small-12 medium-centered large-centered column">
                    <input type="submit" name="send message" value="Send Message">
                </div>
            </form>
        </div>
    </div>
    <!--End of Contact Form-->

and here's the script:

<?php

if (isset($_POST['email']))
//if "email" is filled out, send email
  {
  //send email
  $name = $_POST['name'] ;
  $email = $_POST['email'] ;
  $comments1 = $_POST['comments1'] ;
  $comments2 = $_POST['comments2'] ; 
  mail("info@muzedimage.com", $name, $email, $comments1, $comments2
 , "From:" . $email);
  echo "<script>window.location = 'http://www.muzedimage.com'</script>";
  }
else
//if "email" is not filled out,
  {
  echo "<script>window.location = 'http://www.muzedimage.com/contact'</script>";
  }
?>

I would really appreciate the help guys.

È stato utile?

Soluzione

You have passed wrong arguments to your mail function. Please read the mail() documentation.

The correct format is

mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

In your case below is the correct code.

$to      = 'info@muzedimage.com';
$email   = $_POST['email'] ;
$subject = 'add some subject'; // no subject could lead to email being flagged as spam
$comments1 = $_POST['comments1'] ;
$comments2 = $_POST['comments2'] ; 
$message = $comments1 .  "\n\n" . $comments2;
$headers = "From: $email";

mail($to, $subject, $message, $headers);

You need to use comments how you want to. In this case I assumed that they both consist the main message.

Hope that helps. And always read documentation!!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top