-1

I have attempted several versions of a php form mailer and can not get any of them to work. I am attempting to make it where, when a user clicks 'Submit' the information on the form is auto sent/populated on the email. Currently, no email is being sent, and it is staying on a black website xxxx.com/contact.php. I have been trying to work this out for a week to no avail, even after reading many other similar posts

Here is my html form:

    <form method='post' action='contact.php'>
            <br>
            <br>
            <br>
            <br>

    <h2>
        Contact Us Form
    </h2>
    <table>
        <tr>
            <td>
    <p>
        Fill out the form below with your contact information and questions/comments and click submit.
        We will respond to your inquiry as soon as possible via email. If you prefer a different contact
        method then please provide required information and notate your preference in the comments section.
        I look forward to providing you and your family with great memories that last a lifetime.
    </p>
            </td>
        </tr>
    </table>
    <br>
    <br>

    <label> 
        Your name:<br>
    </label>
    <input type="text" name="customername" size='40' maxlength='50' required><br>

    <label>
        Your Email:<br>
    </label>
    <input type='email' name='emailaddress' size='20' maxlength='254' required><br>

    <label>
        Your phone number (example: 555-555-1234):<br>
    </label>
    <input name='telephone' type='tel' size=3>-<input type='tel' size=3>-<input type='tel' size=4><br>

    <label>
        What product are you interested in?<br>
    </label>
    <input type='radio' name='newshoot' value='new'>New Photo Shoot
    <input type='radio' name='existingshoot' value='existing'>Existing Photo Shoot
    <input type='radio' name='prints' value='prints'>Interested in prints

    <label>
        Street Adress:<br>
    </label>
    <input type="text" name="streetaddress" size='40' maxlength='50'><br>

    <label>
        City:<br>
    </label>
    <input type="text" name="city" size='40' maxlength='50'><br>

    <label>
        State:<br>
    </label>
            <input type="text" name="state" size='40' maxlength='50'><br>

    <label> 
        Zipcode:<br>
    </label>
            <input type="text" name="zipcode" size='40' maxlength='50'><br>

    <label>
        What country are you located in?<br>
    </label>
        <select>
            <option value="USA">United States</option>
            <option value="AFG">Afghanistan</option>

        </select><br>

    <label>
        Comments:<br>
    </label>

        <textarea name='customercomment' rows='5' cols='60' text-align='left' wrap='hard'>

Enter your comments here

    <input type='submit' name='submit' value='Send' />
    <input type='reset' value='Reset'/>

</form>

and here is my php:

<?php

$email_to = "XXXXca@XXXXXto.com";

$email_subject = "Inquiry from: "($customername);    

$first_name = $_POST['customername'];

$email_from = $_POST['emailaddress'];

$telephone = $_POST['telephone'];

$newshoot = $_POST['newshoot'];

$existingshoot = $_POST['existingshoot'];

$prints = $_POST['prints']; 

$streetaddress = $_POST['streetaddress'];

$city = $_POST['city'];

$state = $_POST['state']; 

$zipcode = $_POST['zipcode'];

$comments = $_POST['customercomment'];




$email_message = "Form details below.\n\n".
"Customer Name: ($customername).\n Email: ($email_from).\n Telephone: ($telephone).\n New Shoot? ($newshoot).\n Existing Shoot? ($existingshoot).\n Prints? ($prints).\n Customer's address: ($streetaddress)($city)($state)($zipcode).\n Comments:($comments).\n";



if ($_POST['submit']) 
{
   mail($email_to, $email_subject,$email_message, $email_from) { 
        header('Location: index.html');
   }
}


?>
Misa Lazovic
  • 2,805
  • 10
  • 32
  • 38
T.Bender
  • 49
  • 1
  • 6
  • 1
    What is `mail($email_to, $email_subject,$email_message, $email_from) { ` Looks like you missed the `if` there. Use error reporting.. – chris85 Dec 13 '15 at 00:47
  • 1
    First of all, why do you have curly brackets around the `header()`? Did you accidentally forget to add an `if`? Also, does your `$email_from` contain `"From: "`? Check both of those. Also, does your error log contain any errors? – kzhao14 Dec 13 '15 at 01:07
  • $email_from = $_POST['emailaddress']; no it doesn't. if ($_POST['submit']) { if mail($email_to, $email_subject, $email_message, $email_from) header('Location: index.html'); } I altered this to add the 'if' and took out the {} around header, still not working. Very noob question. What error log are you referring to? – T.Bender Dec 13 '15 at 01:15
  • Display lots of errors before submit from. First check all the data are correctly receive or not when form submit before sending email. if all the data is revived correctly then use mail function. And use check-box instead of radio button and use if(isset($_post['submit'])){enclosing all form data – Samir Karmacharya Dec 13 '15 at 04:35

1 Answers1

-2

you should add checkpoint in the file and than you can see it works or not.

    if ($_POST['submit']) 
    {
      $statu=mail($email_to,$email_subject,$email_message);
mail($email_to,$email_subject,$email_message);
    if($statu==TRUE)
    echo 'email has sent !';
    else
    echo 'email did not send !';
    }

EDIT: Forgive me all friends i did not want to write something like this but i had to. I tried to help he said he saw a blank page so probably he turned off displaying errors. So i wrote this answer to see if there is an error on the page. he thinks this is incorrect. but it helped him to see his mistake. However, he did not thank, also he ordered to me "update your post..." sorry but i think it is not something difficult to be polite.

Ahmet ATAK
  • 342
  • 2
  • 13
  • What are you proposing here? You don't see anything strange in your answer's code? – chris85 Dec 13 '15 at 00:49
  • if you get a blank page probably you turn off display errors: so maybe there is an error. if you add checkpoint you can anderstant your code works or doesn't works if there is no error it will show you the mail has sent – Ahmet ATAK Dec 13 '15 at 00:52
  • You are looking at this code `mail($email_to, $email_subject,$email_message, $email_from) {`? – chris85 Dec 13 '15 at 00:54
  • yes i haven't seen any wrong in your code all you need it works or not – Ahmet ATAK Dec 13 '15 at 00:57
  • This isn't my code. I'm pointing out that your answer is incorrect and won't execute. The PHP is invalid. – chris85 Dec 13 '15 at 00:58
  • did you try? no so how can you be sure it will not work ? we tried to help you $statu=mail($email_to, $email_subject,$email_message, ..... if it works $statu is going toe TRUE if its true it works ! – Ahmet ATAK Dec 13 '15 at 01:01
  • I read the code and KNOW that this `mail($email_to, $email_subject,$email_message, $email_from) { ` is wrong wrong wrong. Here you can run your code though and see it; https://eval.in/484234. – chris85 Dec 13 '15 at 01:02
  • line 4 is in your mail code it should be like this and also turn on displaying errors mail("someone@example.com","My subject",$msg); – Ahmet ATAK Dec 13 '15 at 01:05
  • you forgot to put ";" – Ahmet ATAK Dec 13 '15 at 01:07
  • I'm NOT the OP. I was pointing out your answer was incorrect because it contained invalid PHP. I was stating you should update your "answer" so it is a valid answer. Thanks for downvotes though, I'll be sure to try to assist you in the future. Normally when an update is down that rectifies the issue the downvote is retracted. – chris85 Dec 13 '15 at 14:58