PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
skyser
Forum Newbie
Posts: 4 Joined: Wed Apr 28, 2010 7:25 pm
Post
by skyser » Wed Apr 28, 2010 7:36 pm
dear all,
i used the following code in my contact page in my site but the problem is when i receive the mail from the contact form i get it like this
Name; Ahmad E-Mail: my_mail@gmail.com Tel.: 12345 Message:hello
and i want every field in a line separately like this
Name : ahmad
E-mail :
my_mail@gmail.com
....etc
now please help me editing the code below to get the result i want
thanks alot...
--------------------------------------
Code: Select all
<?php
//start building the mail string
$msg = "Name; $_POST[name] ";
$msg .= "E-Mail: $_POST[email] ";
$msg .= "Tel.: $_POST[tel] ";
$msg .= "Message: $_POST[message] ";
$recipient = "mail@gmail.com";
$subject = "You recived E-mail from a visitor";
$mailheaders = "From:Visitor to Fratelli ";
$mailheaders .= "Reply-to: $_POST[email]";
//send the mail
mail($recipient, $subject, $msg, $mailheaders);
?>
------------------------------------------
Last edited by
Benjamin on Wed Apr 28, 2010 7:49 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
jraede
Forum Contributor
Posts: 254 Joined: Tue Feb 16, 2010 5:39 pm
Post
by jraede » Wed Apr 28, 2010 8:23 pm
Add a line break between each new line you want. "\n".
skyser
Forum Newbie
Posts: 4 Joined: Wed Apr 28, 2010 7:25 pm
Post
by skyser » Thu Apr 29, 2010 4:39 am
can you just edit the above code for me please
i tried many times to do what you said but i can't make it
thanks alot
steven.cottom
Forum Newbie
Posts: 10 Joined: Mon Apr 05, 2010 2:14 pm
Post
by steven.cottom » Thu Apr 29, 2010 5:03 am
Try this:
Code: Select all
<?php
//start building the mail string
$msg = "Name; $_POST[name] \n";
$msg .= "E-Mail: $_POST[email] \n";
$msg .= "Tel.: $_POST[tel] \n";
$msg .= "Message: $_POST[message] \n";
$recipient = "mail@gmail.com";
$subject = "You recived E-mail from a visitor";
$mailheaders = "From:Visitor to Fratelli ";
$mailheaders .= "Reply-to: $_POST[email]";
//send the mail
mail($recipient, $subject, $msg, $mailheaders);
?>
rahulzatakia
Forum Commoner
Posts: 59 Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad
Post
by rahulzatakia » Thu Apr 29, 2010 5:38 am
Hi, just use "\n" for line break. Just use the below code and if you have any query let me know..
Code: Select all
<?php
//start building the mail string
$msg = "Name; $_POST[name]\n \n";
$msg .= "E-Mail: $_POST[email] \n\n";
$msg .= "Tel.: $_POST[tel] \n\n";
$msg .= "Message: $_POST[message]\n\n ";
$recipient = "mail@gmail.com";
$subject = "You recived E-mail from a visitor";
$mailheaders = "From:Visitor to Fratelli ";
$mailheaders .= "Reply-to: $_POST[email]";
//send the mail
mail($recipient, $subject, $msg, $mailheaders);
?>
skyser
Forum Newbie
Posts: 4 Joined: Wed Apr 28, 2010 7:25 pm
Post
by skyser » Thu Apr 29, 2010 7:10 am
thanks alot all,
but the problem still there ,when i recieve the email i got it like this
Name; Ahmad E-Mail:
ahmad@gmail.com Tel.: 123456 Message:hello
i didn't know what to do
rahulzatakia
Forum Commoner
Posts: 59 Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad
Post
by rahulzatakia » Fri Apr 30, 2010 2:06 am
Hi, just try out the below code. I am using the same code and its working absolute fine...
Code: Select all
<?php
//start building the mail string
$msg = "Name; $_POST[name]\n \n";
$msg .= "E-Mail: $_POST[email] \n\n";
$msg .= "Tel.: $_POST[tel] \n\n";
$msg .= "Message: $_POST[message]\n\n ";
$recipient = "mail@gmail.com";
$subject = "You recived E-mail from a visitor";
$mailheaders = "From:Visitor to Fratelli ";
$mailheaders .= "Reply-to: $_POST[email]";
$mailheaders .= "MIME-Version: 1.0" . "\n";
$mailheaders .= "Content-type:text/html;charset=iso-8859-1" . "\n";
//send the mail
mail($recipient, $subject, $msg, $mailheaders);
?>
hypedupdawg
Forum Commoner
Posts: 74 Joined: Sat Apr 10, 2010 5:21 am
Post
by hypedupdawg » Fri Apr 30, 2010 3:59 am
I agree with all the above posts - the \n should work. However, if your e-mail system allows HTML formatting you could also try out using <br/> (line break) formatting like this:
Code: Select all
$msg = "Name; $_POST[name] <br/><br/>";
$msg .= "E-Mail: $_POST[email] <br/><br/>";
$msg .= "Tel.: $_POST[tel]<br/><br/>";
$msg .= "Message: $_POST[message]<br/><br/>";
However, you should try and get the \n style working, as it is more universally accepted.
skyser
Forum Newbie
Posts: 4 Joined: Wed Apr 28, 2010 7:25 pm
Post
by skyser » Fri Apr 30, 2010 6:34 am
Dear rahulzatakia,
i tried your code and the e-mail not arrived to the inbox but the form gives the confirmation page
so i think the "n\" code didn't work.
-----------------------------------
Dear hypedupdawg
i tried your idea and i get
Name; ahmad <br/><br/>E-Mail:
mail@gmail.com <br/><br/>Tel.: 1234561111<br/><br/>Message: hello<br/><br/>
i think it's not woking
hypedupdawg
Forum Commoner
Posts: 74 Joined: Sat Apr 10, 2010 5:21 am
Post
by hypedupdawg » Fri Apr 30, 2010 7:15 am
Yes - unfortunately it is not that widely supported. Just out of interest, have you tried simply writing it as one long string? I know that I find easiest way to format when writing to a .txt document is simply to include the tabs/returns in the comment like this:
Code: Select all
$msg = "Name; $_POST[name]
E-Mail: $_POST[email]
Tel.: $_POST[tel]
Message: $_POST[message]";
However, I appreciate that it might not conserve the whitespace when sending the e-mail - give it a shot, and don't be disappointed if it dosn't work.
rahulzatakia
Forum Commoner
Posts: 59 Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad
Post
by rahulzatakia » Fri Apr 30, 2010 9:44 am
hi..
can you just give your code to view as its working fine on my side.. so i can come to know whats the exact error
jraede
Forum Contributor
Posts: 254 Joined: Tue Feb 16, 2010 5:39 pm
Post
by jraede » Fri Apr 30, 2010 7:27 pm
hypedupdawg wrote: I appreciate that it might not conserve the whitespace when sending the e-mail
I've also found that at least on my email handler, the whitespace is saved. So I can do something like
Code: Select all
$message = "
User: $user
Email: $email
";
And it will appear like that in the email.