Jquery contact form not sending the email with form details

niceoneishere
niceoneishere used Ask the Experts™
on
Hello Experts,
I am using a jquery contact form from this website to make the customer enter some basic info and attach 5 images and then after they click the send button send to my email address.

when i run it the email is not sending , I know i am making mistake somewhere, but it wont thrown any errors.

here is a test link I have set up

http://store.cotintheweb.com/test-contact.html

the email is sent using a ajaxSubmit.php whose code is

<?php

$name = $_POST['name']; // contain name of person
$email = $_POST['email']; // Email address of sender 
$web = $_POST['cotintheweb.com']; // Your website URL
$body = $_POST['Thank you for contacting us. We will get back to you shortly']; // Your message 
$receiver = "niceoneishere@gmail.com" ; // hardcorde your email address here - This is the email address that all your feedbacks will be sent to 
if (!empty($name) & !empty($email) && !empty($body)) {
    $body = "Name:{$name}\n\nWebsite :{$web}\n\nComments:{$body}";
	$send = mail($receiver, 'Contact Form Submission', $body, "From: {$email}");
    if ($send) {
        echo 'true'; //if everything is ok,always return true , else ajax submission won't work
    }

}

?>

I have included a test email address which is a gmail so the email account is real

Open in new window


I dont know how to include in the above php file the images that will be attached,

Thanks and appreciate it
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Looks to me like you forgot an & (ampersand) in your if statement.  Try...

if (!empty($name) && !empty($email) && !empty($body)) {
  ***rest of your code***
}

Author

Commented:
Thanks I changed the code, but i am still not receiving the code. And can you please direct me in how to include the attached images in ajaxSubmit.php file

Thanks
Mail attachments are done through the use of message headers.

See http://www.finalwebsites.com/forums/topic/php-e-mail-attachment-script

For multiple attachments, you can download a script:

http://www.finalwebsites.com/snippets.php?id=41
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Commented:
i found a pbm with ur code

in line number :6

$body = $_POST['Thank you for contacting us. We will get back to you shortly']; // Your message

i hope this should be

$body ='Thank you for contacting us. We will get back to you shortly';

Open in new window


Most Valuable Expert 2011
Top Expert 2016
Commented:
Here is my teaching example of a form-to-email script. It is disabled on my server, for obvious reasons, but you can still use it to see how the form information gets from the HTML part at the bottom into the PHP action script in the top.  And you can copy it, modify it for your own use, install it on your server and tinker with it to see the moving parts.  You would make your custom changes around lines 10-17.
<?php // RAY_form_to_email.php
error_reporting(E_ALL);



// SEND MAIL FROM A FORM



// REQUIRED VALUES ARE PREPOPULATED - CHANGE THESE FOR YOUR WORK
$from  = "NoReply@Your.org";
$subj  = "Contact Form";

// THIS IS AN ARRAY OF RECIPIENTS - CHANGE THESE FOR YOUR WORK
$to[]  = "You@Your.org";
$to[]  = "Her@Your.org";
$to[]  = "Him@Your.org";



// IF THE DATA HAS BEEN POSTED
if (!empty($_POST['email']))
{
    // CLEAN UP THE POTENTIALLY BAD AND DANGEROUS DATA
    $email      = clean_string($_POST["email"]);
    $name       = clean_string($_POST["name"]);
    $telephone  = clean_string($_POST["telephone"]);

    // CONSTRUCT THE MESSAGE THROUGH STRING CONCATENATION
    $content    = NULL;
    $content   .= "You have a New Query From $name" . PHP_EOL . PHP_EOL;
    $content   .= "Tel No: $telephone" . PHP_EOL;
    $content   .= "Email: $email" . PHP_EOL;

    // SEND MAIL TO EACH RECIPIENT
    foreach ($to as $recipient)
    {
        if (!mail( $recipient, $subj, $content, "From: $from\r\n"))
        {
            echo "MAIL FAILED FOR $recipient";
        }
        else
        {
            echo "MAIL WORKED FOR $recipient";
        }
    }
}


// A FORM TO TAKE CLIENT INPUT FOR THIS SCRIPT
$form = <<<ENDFORM
<form method="post">
Please enter your contact information
<br/>Email: <input name="email" />
<br/>Phone: <input name="telephone" />
<br/>Name:  <input name="name" />
<br/><input type="submit" />
</form>
ENDFORM;

echo $form;



// A FUNCTION TO CLEAN UP THE DATA - AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
    // IF MAGIC QUOTES IS ON, WE NEED TO REMOVE SLASHES
    $str = stripslashes($str);

    // REMOVE EXCESS WHITESPACE
    $rgx
    = '/'               // REGEX DELIMITER
    . '\s'              // MATCH THE WHITESPACE CHARACTER(S)
    . '\s+'             // MORE THAN ONE CONTIGUOUS INSTANCE OF WHITESPACE
    . '/'               // REGEX DELIMITER
    ;
    $str = preg_replace($rgx, ' ', $str);

    // REMOVE UNWANTED CHARACTERS
    $rgx
    = '/'               // REGEX DELIMITER
    . '['               // START OF A CHARACTER CLASS
    . '^'               // NEGATION - MATCH NONE OF THE CHARACTERS IN THIS CLASS
    . 'A-Z0-9&+:?_.- '  // CHARACTERS WE WANT TO KEEP
    . ']'               // END OF THE CHARACTER CLASS
    . '/'               // REGEX DELIMITER
    . 'i'               // CASE-INSENSITIVE
    ;
    $str = preg_replace($rgx, NULL, $str);

    return $str;
}

Open in new window

Most Valuable Expert 2011
Top Expert 2016

Commented:
I installed and ran the code snippet posted with the original question, after adding error_reporting(E_ALL) so we can see what the script is doing.  PHP is pretty bad about not telling you when you use undefined variables, etc.
http://www.laprbass.com/RAY_temp_niceoneishere.php Outputs:
Notice: Undefined index: name in /home/websitet/public_html/RAY_temp_niceoneishere.php on line 3
Notice: Undefined index: email in /home/websitet/public_html/RAY_temp_niceoneishere.php on line 4
Notice: Undefined index: cotintheweb.com in /home/websitet/public_html/RAY_temp_niceoneishere.php on line 5
Notice: Undefined index: Thank you for contacting us. We will get back to you shortly in /home/websitet/public_html/RAY_temp_niceoneishere.php on line 6

I think a good debugging strategy would be to get the background script working without jQuery first, and then add the jQuery layer afterwards.

The part about asking the client to attach images -- that requires your action script to handle file uploads, and that is a completely different kind of processing from the form-to-email things.  You might want to post a new question about that.

Best regards, ~Ray

Author

Commented:
thanks everyone I have ended up using formmail.pl. I have split the points equally for all of you

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial