homepage Welcome to WebmasterWorld Guest from 54.221.175.46
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Problem with php form
php form coding
xlilo




msg:3471153
 2:43 pm on Oct 7, 2007 (gmt 0)

hi all,

i have made a form in php code, but i do not know alot about php just the basics, the problem i have is that when i fill in the form and send it the message i get via email has no brakes in it so its all one long sentance with no spaces to devide from the seprate areas of my form, here is the code,

<?php
} else {
error_reporting(0);
$recipient = 'my@example.com';
$from = stripslashes($_POST['Customer_FirstName']);
$msg = "Message from: $from\n\n".stripslashes($_POST['textarea'])
.stripslashes($_POST['Customer_Home_Telephone'])
.stripslashes($_POST['Customer_Email']);
if (mail($recipient, $from, $msg))
echo nl2br("<b>Your Finance Application has been Sent:</b>
To: $recipient
$msg");
else
echo "Message failed to send";
}
?>

now the ode that displays this:

$msg = "Message from: $from\n\n".stripslashes($_POST['textarea'])
.stripslashes($_POST['Customer_Home_Telephone'])
.stripslashes($_POST['Customer_Email']);

is were my error is and i need to add a line brake in between the .stripslashes so that i dont get one long sentance of all infomation together in one word.

anyone help?

thanks,

Xlilo

[edited by: dreamcatcher at 2:50 pm (utc) on Oct. 7, 2007]
[edit reason] Use example.com, thanks. [/edit]

 

ayushchd




msg:3471164
 2:59 pm on Oct 7, 2007 (gmt 0)

You need to send headers too.

Add this at the top :

$headers = "From: u@example.com\r\n";

//specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

n then while sending the mail, send the header too :

if (mail($recipient, $from, $msg, $headers)) {
wteva code
}

n then u can also change this to :

$msg = "Message from: $from <br>".stripslashes($_POST['textarea'])
. "<br>" . stripslashes($_POST['Customer_Home_Telephone'])
. "<br>" . stripslashes($_POST['Customer_Email']);

[edited by: ayushchd at 3:01 pm (utc) on Oct. 7, 2007]

[edited by: dreamcatcher at 5:51 pm (utc) on Oct. 7, 2007]
[edit reason] Use example.com, thanks. [/edit]

xlilo




msg:3471165
 3:00 pm on Oct 7, 2007 (gmt 0)

also (but not inportant but will be nice) how do i get the form to send the message from the customers email address? so i can reply directly from the email form message.

ahmedtheking




msg:3471169
 3:02 pm on Oct 7, 2007 (gmt 0)

Read up on mail: [uk2.php.net...]

xlilo




msg:3471171
 3:05 pm on Oct 7, 2007 (gmt 0)

like this?

<?php
} else {
error_reporting(0);
$headers = "From: u@example.com\r\n";

//specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$recipient = 'info@example.com';
$from = stripslashes($_POST['Customer_FirstName']);
$msg = "Message from: $from\n\n".stripslashes($_POST['textarea'])
.stripslashes($_POST['Customer_Home_Telephone'])
.stripslashes($_POST['Customer_Email']);
if (mail($recipient, $from, $msg, $headers))
echo nl2br("<b>Your Finance Application has been Sent:</b>
To: $recipient
$msg");
else
echo "Message failed to send";
}
?>

[edited by: dreamcatcher at 5:51 pm (utc) on Oct. 7, 2007]
[edit reason] Use example.com, thanks. [/edit]

ayushchd




msg:3471173
 3:08 pm on Oct 7, 2007 (gmt 0)

Also you can change $msg :

$msg = "Message from: $from <br>".stripslashes($_POST['textarea'])
. "<br>" . stripslashes($_POST['Customer_Home_Telephone'])
. "<br>" . stripslashes($_POST['Customer_Email']);

Note : Since you are now sending headers, u can edit your message juss like editing HTML. You can use tables n all those stuffs..if u've noticed, i have used <br> which is an HTML tag

ayushchd




msg:3471174
 3:08 pm on Oct 7, 2007 (gmt 0)

Yes.

Also you can change $msg :

$msg = "Message from: $from <br>".stripslashes($_POST['textarea'])
. "<br>" . stripslashes($_POST['Customer_Home_Telephone'])
. "<br>" . stripslashes($_POST['Customer_Email']);

Note : Since you are now sending headers, u can edit your message juss like editing HTML. You can use tables n all those stuffs..if u've noticed, i have used <br> which is an HTML tag

xlilo




msg:3471177
 3:12 pm on Oct 7, 2007 (gmt 0)

thanks for your reply, and its working too, however in the header code : $headers = "From: my@example.com\r\n"; i put my email and it apears it sends from my email, how do i get it to send from the customers email?

ayushchd




msg:3471192
 3:46 pm on Oct 7, 2007 (gmt 0)

You can do this :

$headers = "From: ". $_POST['Customer_Email'] ."\r\n";

instead of :
$headers = "From:u@example.com\r\n";

[edited by: dreamcatcher at 5:50 pm (utc) on Oct. 7, 2007]
[edit reason] Use example.com, thanks. [/edit]

xlilo




msg:3471193
 3:59 pm on Oct 7, 2007 (gmt 0)

thank you so much, this has worked and now i can go ahead with adding all the feilds into the sending script. when i get an email from the form i get the message but it shows the <br> tags in the message, this is not realy a big problem as i can just edit the message in dreamweaver but it would be perfect if it would just put them on new lines in outlook automaticaly.

example,

email for send this :

customer number<br>customer name<br> etc etc

idealy would like :

customer number
customer name
etc etc

maybe its outlook but like i said, im not to botherd as you have manged to get my form working properly and you answerd my questions with perfection.

Thanks Again,

Xlilo

ayushchd




msg:3471198
 4:05 pm on Oct 7, 2007 (gmt 0)

Does it show the <br> tag only in outlook, or in hotmail,yahoo,etc. too.

If it shows <br> in outlook, i dont know the solution about it. :(

ayush

xlilo




msg:3471200
 4:12 pm on Oct 7, 2007 (gmt 0)

not sure if it show it in a web based client, but it does not realy bother me with the tag showing, i can just edit it in dreamweaver,

thanks for all your help, your a good programmer.

ayushchd




msg:3471206
 4:29 pm on Oct 7, 2007 (gmt 0)

thanks

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved