473,473 Members | 4,208 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sending an email via mail() - message is all jumbled up!

daJunkCollector
76 New Member
I created a form in flash. The user can fill out each field of the form and submit the information to the $sendTo email address just fine, however, I receive the email section, $message, all jumbled up! I need to put a line break between each section so that the email I receive is legible.

I want each variable to appear on its own line.

I assume there is an extremely easy fix for this, but I have been searching for hours. Your help is very much appreciated.




[PHP]<?php
$sendTo = "me@gmail.com";
$subject = "Subject of the email";

$headers = "From: " . $_POST["contactVar"];
$headers .= "<" . $_POST["emailVar"] . ">\r\n";
$headers .= "Reply-To: " . $_POST["emailVar"] . "\r\n";
$headers .= "Return-Path: " . $_POST["emailVar"];
$message = $_POST["emailVar"];
$message .= $_POST["agencyVar"];
$message .= $_POST["address1Var"];
$message .= $_POST["address2Var"];
$message .= $_POST["cityVar"];
$message .= $_POST["stateVar"];
$message .= $_POST["zipcodeVar"];
$message .= $_POST["phoneVar"];
$message .= $_POST["faxVar"];
$message .= $_POST["websiteVar"];
$message .= $_POST["commentsVar"];

mail($sendTo, $subject, $message, $headers);

?>[/PHP]
Jun 19 '07 #1
3 2276
pbmods
5,821 Recognized Expert Expert
Changed thread title to better describe the problem (did you know that threads whose titles contain phrases such as 'please help' actually get FEWER responses?).

Heya, daJunkCollector. Welcome to TSDN!

You are putting newlines in your source code... but not your message body :(

Try this instead:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     $sendTo = "me@gmail.com";
  3.     $subject = "Subject of the email";
  4.  
  5.     $headers = "From: $_POST[contactVar]";
  6.     $headers .= "<$_POST[emailVar]>\r\n";
  7.     $headers .= "Reply-To: $_POST[emailVar]\r\n";
  8.     $headers .= "Return-Path: $_POST[emailVar]";
  9.  
  10.     $message = <<<EOT
  11. $_POST[emailVar]
  12. $_POST[agencyVar]
  13. $_POST[address1Var]
  14. $_POST[address2Var]
  15. $_POST[cityVar]
  16. $_POST[stateVar]
  17. $_POST[zipcodeVar]
  18. $_POST[phoneVar]
  19. $_POST[faxVar]
  20. $_POST[websiteVar]
  21. $_POST[commentsVar]
  22. EOT;
  23.  
  24.     mail($sendTo, $subject, $message, $headers); 
  25. ?>
  26.  
http://us2.php.net/manual/en/languag...syntax.heredoc
Jun 19 '07 #2
digitalpbk
4 New Member
alternatively you can mail the entire in HTML format so you just need to add [HTML]<br/>[/HTML] after every line.

[PHP]
function sendHTMLMail($name,$email,$body,$title)
{
//recipient
$to = $email ;

// subject
$subject = "";

//HTML message TODO: Modify below
$message = "
<html>
<head>
<title>$title</title>
</head>
<body>
$body
</body>
</html>
";

// To send HTML mail, the Content-type header must be set
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";

// Additional headers
$headers .= "To: $name <$email>" . "\r\n";
$headers .= "From: Nobody<no-reply@noreply.com>" . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

}
[/PHP]
Jun 20 '07 #3
daJunkCollector
76 New Member
Totally awesome. Both solutions worked great. I was in the right ballpark but just could not figure it out myself. Thank you very very much guys.
Jun 20 '07 #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...
3
by: VB Programmer | last post by:
I have an ASPX page where I send out emails through my mail server mail.MyDomain.com. When I send emails to MyName@MyDomain.com it sends PERFECTLY. When I try sending an email to any other address...
6
by: Eduardo Rosa | last post by:
Somebody knows how I queue email using .Net? thanks a lot
9
by: B-Dog | last post by:
I've built a small app that sends mail through our ISP's SMTP server but when I try to send through my local exchange server I get CDO error. Does webmail use SMTP or does it strictly rely on...
3
by: Ant | last post by:
Hi, I'm using the MailMessage & smtpMail classes in System.Web.Mail to send mail, however it's not sending any emails. I'm using it on a Windows 2003 server. The simplest way to use this is...
6
by: Anuradha | last post by:
Dear All How can i send mails using vb.net Thanx all
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
2
by: =?Utf-8?B?QWRl?= | last post by:
HI All, I am encountering the following error when I try to send an email through a SMTP server. I believe the problem lies with the authentication part when the network crednetials are used,...
9
by: JoeP | last post by:
Hi All, How can I find the reason for such an error: Failure sending mail. Some Code... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.