473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

My form data not going through email...

Hai there,

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

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
Oct 2 '09 #1
2 2253
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!
Oct 2 '09 #2
As a partial correction/addendum to my last post, see this entry on php.net:

Variable functions

Hope your script is working now.
Oct 14 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
1
by: Jacek | last post by:
Hi. I have some problem. Im not sure if this is problem with asp or maybe with iis. I have a form like this - file (file1.asp) <HTML> <HEAD> <TITLE> New Document </TITLE> </HEAD> <BODY>...
8
by: Brian F | last post by:
Exactly what the subject says. I have an ASP page that I want my C# windows application to open in Internet Explorer, and if possible have it send along a list of values from a list box. Thank you.
6
by: Esteban404 | last post by:
I'm trying to create a preview shot of a record being edited, so I want to take the current state and pass it to a instance of a form I have. I've tried to create a dataView and pass that, but it...
4
by: Adam Clauss | last post by:
This may be more of a Visual Studio question than a C# question, but it came up within the context of a C# app, so here it is. In a Windows Form or a Web Form application, you can drag various...
5
by: amanatio | last post by:
I have a huge form with many data bound controls on it and 34 tables in database (and of course 34 data adapters and 34 datasets). The form is extremely slow to design (huge delay when I go to code...
27
by: Scott | last post by:
I've been trying to come up with a way to ensure user input is coming from the form on my site, and not auto-submitted from elsewhere, and I don't want to use the "enter the code shown in the...
22
by: Zytan | last post by:
I have public methods in a form. The main form calls them, to update that form's display. This form is like a real-time view of data that is changing. But, the form may not exist (it is...
15
by: Kevin Davis | last post by:
Hello, I'm a new person when it comes to PHP and I have a quick question. I would like to create a form that will allow the user to add more information using the same form in case they have...
19
by: klenwell | last post by:
Another request for comments here. I'd like to accomplish something like the scheme outlined at this page here: http://tinyurl.com/3dtcdr In a nutshell, the form uses javascript to hash...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.