Page 1 of 1
I want a help with my code
Posted: Wed Apr 28, 2010 7:36 pm
by skyser
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);
?>
------------------------------------------
Re: I want a help with my code
Posted: Wed Apr 28, 2010 8:23 pm
by jraede
Add a line break between each new line you want. "\n".
Re: I want a help with my code
Posted: Thu Apr 29, 2010 4:39 am
by skyser
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
Re: I want a help with my code
Posted: Thu Apr 29, 2010 5:03 am
by steven.cottom
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);
?>
Re: I want a help with my code
Posted: Thu Apr 29, 2010 5:38 am
by rahulzatakia
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);
?>
Re: I want a help with my code
Posted: Thu Apr 29, 2010 7:10 am
by skyser
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
Re: I want a help with my code
Posted: Fri Apr 30, 2010 2:06 am
by rahulzatakia
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);
?>
Re: I want a help with my code
Posted: Fri Apr 30, 2010 3:59 am
by hypedupdawg
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.
Re: I want a help with my code
Posted: Fri Apr 30, 2010 6:34 am
by skyser
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
Re: I want a help with my code
Posted: Fri Apr 30, 2010 7:15 am
by hypedupdawg
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.
Re: I want a help with my code
Posted: Fri Apr 30, 2010 9:44 am
by rahulzatakia
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
Re: I want a help with my code
Posted: Fri Apr 30, 2010 7:27 pm
by jraede
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.