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

PHP mail() sending emails wrong

So I am trying to send an email to the server admin to notify new support ticket, and one to the client to tell them thank you for contacting us. Server admin email receves the info correct but the client email gets both messages in one email like what is showen below. What is the problem?

===========email=============
Hello!

Thank you for reaching out. We will be in contact with you as soon as possible!:

Name:
E-mail:
Account-Number:
Ticket Number: 814

Message:
Hello!

Your contact form has been submitted by:

Name:
E-mail:
Account-Number:
IP:


Message:
Testing of the 2way mesage system

End of message


End of message


======CODE=========

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /* Set e-mail recipient */
  3. $myemail  = "";
  4.  
  5. /* Get submitent ip address */
  6. $ip=$_SERVER['REMOTE_ADDR'];
  7.  
  8. /* Check all form inputs using check_input function */
  9. $name      = check_input($_POST['name'], "Enter your name");
  10. $subject   = check_input($_POST['subject']);
  11. $email     = check_input($_POST['email']);
  12. $acctnum   = check_input($_POST['acctnum']);
  13. $message   = check_input($_POST['message'], "Write your comments");
  14.  
  15.  
  16. /* If e-mail is not valid show error message */
  17. if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
  18. {
  19.     show_error("E-mail address not valid");
  20. }
  21.  
  22. /* Generate ticket number */
  23. $ticketnum = mt_rand(1,1000);
  24.  
  25. /* Let's prepare the message for the e-mail */
  26. $message = "Hello!
  27.  
  28. Your contact form has been submitted by:
  29.  
  30. Name: $name
  31. E-mail: $email
  32. Account-Number: $acctnum
  33. IP: $ip
  34.  
  35.  
  36. Message:
  37. $message
  38.  
  39. End of message
  40. ";
  41.  
  42. /* Prepare the email to the client */
  43. $subject2 = "Ticket: $ticketnum";
  44.  
  45. $message2 = "Hello!
  46.  
  47. Thank you for reaching out. We will be in contact with you as soon as possible!:
  48.  
  49. Name: $name
  50. E-mail: $email
  51. Account-Number: $acctnum
  52. Ticket Number: $ticketnum
  53.  
  54. Message:
  55. $message
  56.  
  57. End of message
  58. ";
  59.  
  60. /* send emails */
  61. mail($myemail, $subject, $message);
  62. mail($email, $subject2, $message2);
  63.  
  64. /* Redirect visitor to the thank you page */
  65. header('Location: ../thanks.html');
  66. exit();
  67.  
  68. /* Functions we used */
  69. function check_input($data, $problem='')
  70. {
  71.     $data = trim($data);
  72.     $data = stripslashes($data);
  73.     $data = htmlspecialchars($data);
  74.     if ($problem && strlen($data) == 0)
  75.     {
  76.         show_error($problem);
  77.     }
  78.     return $data;
  79. }
  80.  
  81. function show_error($myError)
  82. {
  83. ?> <html> <body> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> </body> </html> <?php
  84. exit();
  85. }
  86. ?>
Oct 24 '14 #1
3 1277
Rabbit
12,516 Expert Mod 8TB
The problem is you overwrite the $message variable with the body of the first email. And then you go and insert that value into the second message.
Oct 24 '14 #2
Exequiel
288 256MB
right now are you using the local server or did you already uploaded on line? because there are some changes you must do local and online.
Oct 24 '14 #3
I fixed it! Rabbit was right, thanks guys.
Oct 24 '14 #4

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

Similar topics

0
by: praba kar | last post by:
Dear All, I have doubt regarding mail sending smtplib module. The below code is I used to send a mail. ########################################## import email.Message import email.Utils...
11
by: Ron Vecchi | last post by:
I've used System.Web.Mail before but have never had the need to send attchemnets through it...until now. A client of mine would like a form on the website to allow a user to type up a message and...
3
by: VB Programmer | last post by:
My company has it's own webserver, which is going to host our ASP.NET web application. We want the website to be able to send out emails. 1. What do I need on the server so that it has the...
2
by: Mr. x | last post by:
Hello, I am sending emails with Hebrew contents. When receiving emails - I cannot see the Hebrew characters (it is not outlook express configuration, because when receiving emails from friends -...
3
by: Arek | last post by:
Hey, I have a question, what are the possibilities of sending emails using ASP.net. (and VB.net) What I think is that user can send automatic reminder if he check box on the form and submit. Do...
3
by: A | last post by:
Hi all! I would like to ask a question on sending emails... I have a web application that requires sending emails using email templates. The templates that I've made are separate HTML files...
2
by: Jodye Roebuck | last post by:
I have a program that's been automatically generating and sending emails flawlessly. My clients workstation had an automatic Microsoft security update done on it.. and now it's bombing on this...
7
by: mlevit | last post by:
Hi, I send out emails through MS Access via SendObject. I would like to know if there is a way of getting rid of the Outlook Security Popup that comes up every time an email is about to be sent. ...
2
by: sam | last post by:
Hi, I made asp.net website. I send e-mail via asp.net page to receiver but receiver cannot get email. I use smartertool Server SMTP. Sending and receiving to localhost is working. Sending...
4
Ali Rizwan
by: Ali Rizwan | last post by:
Hello all, I have made a web page, Now i want to add some features like sending emails. I want to use HTML code to send emails. Email text will be retrieved by combining the text of two text...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.