473,395 Members | 1,846 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,395 software developers and data experts.

I have problem in sending message in contact us form

25
Hi there,

I have created a free website at Xtreemhost site. They are saying that they support Send email in the free hosting. Anyway I tried to set a page "Contact Us" and I want the visitor when he send me a message so it will be sent to my Gmail with his name as well. I tried a lot of code when I did search in Google but nothing is working, I don't know where is the problem. The code seems okay and it says that "meesage has been sent" but when I go to my email Gmail I don't find any email from my website.

I hope someone can really help me to fix this problem.

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. if ($_POST["email"]<>'') { 
  3.     $ToEmail = 'wazxcv@gmail.com'; 
  4.     $EmailSubject = 'Site contact form '; 
  5.     $mailheader = "From: ".$_POST["email"]."\r\n"; 
  6.     $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
  7.     $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
  8.     $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
  9.     $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
  10.     $MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>"; 
  11.     mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
  12. ?> 
  13. Your message was sent
  14. <?php 
  15. } else { 
  16. ?> 
  17. <html><body>
  18. <form action="new.php" method="post">
  19. <table width="400" border="0" cellspacing="2" cellpadding="0">
  20. <tr>
  21. <td width="29%" class="bodytext">Your name:</td>
  22. <td width="71%"><input name="name" type="text" id="name" size="32"></td>
  23. </tr>
  24. <tr>
  25. <td class="bodytext">Email address:</td>
  26. <td><input name="email" type="text" id="email" size="32"></td>
  27. </tr>
  28. <tr>
  29. <td class="bodytext">Comment:</td>
  30. <td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td>
  31. </tr>
  32. <tr>
  33. <td class="bodytext">&nbsp;</td>
  34. <td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td>
  35. </tr>
  36. </table>
  37. </form> </body></html>
  38. <?php 
  39. }; 
  40. ?>

Another example I used as well but didn't work well with me. I installed phpmailer inside a folder.

Expand|Select|Wrap|Line Numbers
  1. <?php  
  2.  
  3. require("class.phpmailer.php"); // path to the PHPMailer class
  4.  
  5. $mail = new PHPMailer();  
  6.  
  7. $mail->IsSMTP();  // telling the class to use SMTP
  8. $mail->Mailer = "smtp";
  9. $mail->Host = "ssl://smtp.gmail.com";
  10. $mail->Port = 465;
  11. $mail->SMTPAuth = true; // turn on SMTP authentication
  12. $mail->Username = "yourusername@gmail.com"; // SMTP username
  13. $mail->Password = "yourpassword"; // SMTP password 
  14.  
  15. $mail->From     = "email address sender";
  16. $mail->AddAddress("email address receiver");  
  17.  
  18. $mail->Subject  = "First PHPMailer Message";
  19. $mail->Body     = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
  20. $mail->WordWrap = 50;  
  21.  
  22. if(!$mail->Send()) {
  23. echo 'Message was not sent.';
  24. echo 'Mailer error: ' . $mail->ErrorInfo;
  25. } else {
  26. echo 'Message has been sent.';
  27. }
  28. ?>

Actually I checked the Spamer folder doesn't have any email, so the problem is that I can't get any email from my website.

I found here some website is talking about my problem is well but actually I tried to implement what are they saying but I couldn't solve my problem

http://xtreemhost.com/2010/04/11/how-to-send-e-mails-via-smtp-with-phpmailer-and-gmail/#codesyntax_1

http://www.google.com/support/forum/p/Google%20Apps/thread?tid=2def4c3c8f1f7397&hl=en

Please give me your hand in fixing this problem I did a lot of search on google before asking here. Thanks in advanced.
Nov 16 '10 #1
2 2434
dlite922
1,584 Expert 1GB
You're printing your message has been sent no matter what. Shouldn't you only send that message when mail() function returns true?

You're not even capturing the output of the mail() function.

see php.net/mail.

I'm guessing it will return false. You need a working smtp server (mail server) and authentication to use it to successfully "send" an email.

Receiving an email is a whole set of different problems. gmail might choose to block your domain completely if it looks suspicious or Domain/MX and SPF settings are out of wack.

Dan
Nov 16 '10 #2
RomeoX
25
Thanks for replying to me. Actually my webhost telling that they totally support SMTP for free, but they told me to Request a ticket if I need them to fix my code but they charge tooooooo much. They told me it's code problem, so what should I do now. Please I'm waiting anyone to help. Thanks
Nov 18 '10 #3

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

Similar topics

9
by: Jason | last post by:
I'm struggling with this email code and I'm not php freak since I'm starting to learn php stuff. Could use some help... It seems that I get too many parse errors all over and cannot figure went...
20
by: Steevo | last post by:
For some reason I can't seem to get the contact form on our website to work any longer. I think I must have something wrong in the script because I keep getting an "Internal Server Error" upon...
3
by: mirkobonet | last post by:
The idea is creating a contact form using mailto so it work with the regular mail program. (the server doesn't support php or asp) I created the form and the function is function mailMe(form){...
1
by: Gregor | last post by:
Hi, I got a service (written in C#) that sends out messages to a third party system. The messages contain encoded attachments. Everything works fine as long as the messages are small (say <...
4
by: rodey | last post by:
I am setting up a contact form on my website and there are a couple things I'm not sure about ... The form will not be sent to a database, I just want to take the contents and have it emailed to me...
8
by: chromis | last post by:
Hi, I'm writing a contacts section for a cms on a website, I've decided to write the section in OO code. So far I have my Contacts object and a page structure I would use for a procedural site. ...
3
by: jerry101 | last post by:
Okay, so I have no knowledge with ASP and I was asked to look at this contact form because the emails aren't delivering. I'll post the whole page of code, because I am unsure at what is what...
3
by: tonyb68 | last post by:
Hi - Not sure if this is exactly the right forum to enter this is - but need to start somewhere as I don't know where it's not working. I have a contact form on a flash website, when the submit...
2
by: Ecot | last post by:
Hi all, I have not got any php knowledge and I have found a php code on the net and using it to send e-mail from a web html form.So far the form and the code works fine. I have the following php...
4
by: luke noob | last post by:
This is my HTML... <head> <script type="text/javascript" src="js/jquery-1.2.6.pack.js"></script> <script type="text/javascript" src="js/script.js"></script> </head> <body>
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.