Connecting Tech Pros Worldwide Help | Site Map

My form data not going through email...

Member
 
Join Date: Jul 2008
Location: Malaysia
Posts: 38
#1: Oct 2 '09
Hai there,

I have doing php code for form data to be send to email.
But it is showing...

Quote:
Your message could not be sent at this time. Please try again.
Here is my code for html form...
Expand|Select|Wrap|Line Numbers
  1. <body>
  2.  
  3.     <div id="emailform">
  4.     <form action="email-thankyou.php" method="post" name="contactForm" onsubmit="return validateForm(this);">
  5.  
  6. <p><strong>Name:</strong> <input name="name" type="text" size="40" /></p>
  7. <p><strong>Email:</strong> <input name="email" type="text" size="40" /></p>
  8. <p><strong>Message:</strong></p>
  9. <p><textarea name="message" rows="4" cols="50"></textarea></p>
  10.  
  11. <div id="buttons"><input type="submit" value="Send Email">&nbsp;&nbsp;<input type="reset" value="Reset"></div>
  12.  
  13. </form>
  14. </div>        
  15. </body>
  16.  
Here is my code for php file....
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.     // Grab the form vars
  4.     $email = (isset($_POST['email'])) ? $_POST['email'] : '' ;
  5.     $message = (isset($_POST['message'])) ? $_POST['message'] : '' ;
  6.     $name = (isset($_POST['name'])) ? $_POST['name'] : '' ;
  7.  
  8.     // Check for email injection
  9.     if (has_emailheaders($email)) {
  10.         die("Possible email injection occuring");
  11.     }
  12.  
  13.     $sent = @mail("user@example.com", "Subject of the email ", "Name: $name\n Email: $email\n\n $message", "From: $email");
  14.  
  15.         if ($sent ) { 
  16.             echo "Thank you for your inquiry, Your message has been received. <br>We will get back to you as soon as we can."; 
  17.         } else { 
  18.             echo "Your message could not be sent at this time. Please try again."; 
  19.         }
  20. function has_emailheaders($text) {
  21.     return preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i", $text);
  22. }
  23. ?>
  24.  

Is it because im using yahoomail or gmail as a receiver's email.
Please help me....
Im a newbie in php coding.

Regards,
Meshack
Newbie
 
Join Date: Aug 2008
Posts: 11
#2: Oct 2 '09

re: My form data not going through email...


The receiver's e-mail should not matter. This is an untested theory but I think the problem may be that you're assigning a function call to a variable. That works in JavaScript but it's a bit unorthodox in PHP. Try eliminating the $sent variable and just call
Expand|Select|Wrap|Line Numbers
  1. if(mail($to, $sub, $msg, $from)){
  2. //success
  3. }else{
  4. //problem!
  5. }
Also if you remove that @ sign from in front of your call to mail() just for testing purposes, the system might display a helpful error message. You can put it back when your site goes into production.

Good luck!
Newbie
 
Join Date: Aug 2008
Posts: 11
#3: Oct 14 '09

re: My form data not going through email...


As a partial correction/addendum to my last post, see this entry on php.net:

Variable functions

Hope your script is working now.
Reply