1

I have a template for a website, and I want to customize the message sender there. I saw this form to help out with the implementation of it.

the php file looks like this:

<?php
echo 'testing php'; 
$name = $_POST['name']; // contain name of person
$email = $_POST['email']; // Email address of sender 
$web = $_POST['web']; // Your website URL
$body = $_POST['text']; // Your message 
$receiver = "[email protected]" ; // hardcorde your email address here - This is the email address that all your feedbacks will be sent to 

$body = "Name:{$name}\n\nWebsite :{$web}\n\nComments:{$body}";
$send = mail($receiver, 'Contact Form Submission', $body, $email);
if ($send) {
    echo 'true'; //if everything is ok,always return true , else ajax submission won't work
}
?>

UPDATE

I've managed to call the php file like this:

<form id="form" method="post" action="ajaxSubmit.php" > 
                <fieldset> 
                <label><input type="text" id="name" name="name" value="Name" onBlur="if(this.value=='') this.value='Name'" onFocus="if(this.value =='Name' ) this.value=''"></label>
                  <label><input type="text" id="email" name="email" value="Email" onBlur="if(this.value=='') this.value='Email'" onFocus="if(this.value =='Email' ) this.value=''"></label> 
                <label><input type="text" id="web" name="web" value="Phone" onBlur="if(this.value=='') this.value='Phone'" onFocus="if(this.value =='Phone' ) this.value=''"></label>
                  <label><textarea id="text" name="text" onBlur="if(this.value==''){this.value='Message'}" onFocus="if(this.value=='Message'){this.value=''}">Message</textarea></label> 
                <input type="reset" /> 
                <input type="submit" /> 
                </fieldset> 
                </form>

but when I run this I get teh following ERROR

Warning: mail() [function.mail]: SMTP server response: 550 The address is not valid. in C:\wamp\www\forSale\dataTable\ajaxSubmit.php on line 17

but then I check the vallues of the variables, they are correct. what does that mean?

12
  • 1
    "always hits failure" - what kind of failure? have you turned on php error reporting? Commented Apr 30, 2012 at 19:24
  • 1
    The ajax call fires with this code? Your onclick states sendemailFunction() but the function defined is sendEmail(). I assume this doesn't reflect your actual code. Commented Apr 30, 2012 at 19:26
  • Are you able to send emails from php, without ajax? Commented Apr 30, 2012 at 19:30
  • at MAtt K, I'm kinda new to php, so I dunno how to debug php code. I degun the javascript through firebug and it goes into the sendEmail(); but goes through it. I think it might not even be hitting the php code, how can I check that? Commented Apr 30, 2012 at 19:31
  • You didn't specify how the data is being sent via AJAX. iirc, this means that AJAX defaults to $_GET. This is easy enough to test... Commented Apr 30, 2012 at 19:31

3 Answers 3

1

As I said in the chat, you should try by starting from the ground up by first submitting the form normally, then improve it by validating it with javascript and after that try to submit it with ajax.

If you modify the form back to basics you get:

<form id="form" method="post" action="ajaxSubmit.php" >
    <fieldset>
        <input type="text" id="name" name="name" value="Name" 
                    onBlur="if(this.value=='') this.value='Name'" 
                    onFocus="if(this.value =='Name' ) this.value=''" />
        <input type="text" id="email" name="email"  value="Email" 
                    onBlur="if(this.value=='') this.value='Email'"
                    onFocus="if(this.value =='Email' ) this.value=''" />
        <input type="text" id="web" name="web"  value="Phone" 
                    onBlur="if(this.value=='') this.value='Phone'" 
                    onFocus="if(this.value =='Phone' ) this.value=''" />
        <textarea id="text" name="text" value="Message"
                    onBlur="if(this.value==''){this.value='Message'}" 
                    onFocus="if(this.value=='Message') this.value=''}" />  
        <input type="reset" />
        <input type="submit" />
    </fieldset>  
</form>
Sign up to request clarification or add additional context in comments.

1 Comment

And the error I got was pretty bad one. It was really difficult to track down, so this is what I did that works. Since I'm using WAMP, I had to modify it's php.ini file, so I changed the sendmail_from to one of the e-mail addresses I have on my hMailServer. I dunno why it works, but it does. It works fine now.
1

Unless my lack of coffee is playing tricks on my eyes, you have not specified a name attribute on those inputs. $_POST does not contain the ID of the element, but rather the 'name' and 'value' attributes.

e.g:

<input type="text" id="name" value="Name" name="name" ...

edit: to debug this theory, try outputting the values of the $_POST variables in your PHP file

1 Comment

oh, I didn't know that, well I've added name= "name" to them
1

add attribute name="field_name" to the input fields. This might fix the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.