mail()

PHP coding talk.

Moderator: Moderators

mail()

Postby DooBDee on Tue May 31, 2005 9:08 pm

Greetings,

I am new the the mail() function,

Can somebody explain why this code does not work, and how ti can be corrected?

Code: Select all
<?php
if(!empty($_POST['name']) || (!empty($_POST['email']) || (!empty($_POST['websitename']) || (!empty($_POST['category']) || (!empty($_POST['colourscheme']) || (!empty($_POST['domain']) || (!empty($_POST['logo']) || (!empty($_POST['navi']) (!empty($_POST['add'])) 

mail('jack@doobdee.net', stripslashes($_POST['subject']), stripslashes($_POST['name']), stripslashes($_POST['email']), stripslashes($_POST['websitename']), stripslashes($_POST['category']), stripslashes($_POST['colourscheme']), stripslashes($_POST['domain']), stripslashes($_POST['logo']), stripslashes($_POST['navi']), stripslashes($_POST['add']), 'From: ' . stripslashes($_POST['email']) . ' <' . stripslashes($_POST['name']) . '>');   //Change Email Adress
}
?>


Kind regards,

DooBDee

PS : Also how do you put a line between each $_POST?
DooBDee
Website Ninja
DooBDee.net
User avatar
DooBDee
Moderator
Moderator
 
Posts: 3530
Joined: Tue Mar 01, 2005 6:28 pm
Location: DooBDee.net

Postby kvfb97 on Tue May 31, 2005 9:20 pm

Dont understand what code you have at all but the mail function works like this...
Code: Select all
mail( string to, string subject, string message)

mail( “to@emailaddress.com”, “This is my subject line”, “This is my message.  \n The
\n to the left of this text makes a new line”)
Tip: Don't argue with idiots, they'll drag you down to their level and beat you with experience.
User avatar
kvfb97
Registered User
Registered User
 
Posts: 1774
Joined: Mon Aug 02, 2004 8:18 am
Location: Northern Ireland, UK

Postby DooBDee on Tue May 31, 2005 9:25 pm

im using mail form as part as $_POST from a form.

I am using the same format line as you are using, bu i am wantint to email server different fields as the message line.

The first part checks to see if it exists and striplashes
DooBDee
Website Ninja
DooBDee.net
User avatar
DooBDee
Moderator
Moderator
 
Posts: 3530
Joined: Tue Mar 01, 2005 6:28 pm
Location: DooBDee.net

Postby kvfb97 on Tue May 31, 2005 9:33 pm

Well how about something like this, after you check if its there...
Code: Select all
<?php

$mail = 'me@me.com';
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$websitename = $_POST['websitename'];
$catergory = $_POST['catergory'];

mail($mail, $subject, $name.'n/'.$email.'n/'.$websitename.'/n'.$catergory)

?>
Tip: Don't argue with idiots, they'll drag you down to their level and beat you with experience.
User avatar
kvfb97
Registered User
Registered User
 
Posts: 1774
Joined: Mon Aug 02, 2004 8:18 am
Location: Northern Ireland, UK

Postby DooBDee on Tue May 31, 2005 9:57 pm

Greetings,

Thanks for the reply.

I get this:

awdn/adwn/daw/n/nadw/ndaw/ndaw/nawd/nadw/nadw

the /n are still there

is n/ supposed to be

\n ?
DooBDee
Website Ninja
DooBDee.net
User avatar
DooBDee
Moderator
Moderator
 
Posts: 3530
Joined: Tue Mar 01, 2005 6:28 pm
Location: DooBDee.net

Postby PostBot on Tue May 31, 2005 10:54 pm

Use "\n" and make sure its double quotes, not single quotes because special commands like \n are not parsed in single quoted string.
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby kvfb97 on Wed Jun 01, 2005 2:57 pm

Sorry, im learning myself.
Tip: Don't argue with idiots, they'll drag you down to their level and beat you with experience.
User avatar
kvfb97
Registered User
Registered User
 
Posts: 1774
Joined: Mon Aug 02, 2004 8:18 am
Location: Northern Ireland, UK

Postby DooBDee on Wed Jun 01, 2005 7:08 pm

same!

Thanks for the input kvfb97
DooBDee
Website Ninja
DooBDee.net
User avatar
DooBDee
Moderator
Moderator
 
Posts: 3530
Joined: Tue Mar 01, 2005 6:28 pm
Location: DooBDee.net

Postby DooBDee on Thu Jun 02, 2005 3:39 pm

[quote user="CyberAlien" post="37479"]Use "\n" and make sure its double quotes, not single quotes because special commands like \n are not parsed in single quoted string.[/quote]

So this:

Code: Select all
mail ($mail, $subject, Name: .$name."\n".Email: .$email."\n".Website Name: .$websitename."\n".Colour Scheme: .$colourscheme.Category: .$catergory."\n".Domain: .$domain."\n".Logo: .$logo."\n".Navigation: .$navi."\n".Additional Info: .$add);

?
DooBDee
Website Ninja
DooBDee.net
User avatar
DooBDee
Moderator
Moderator
 
Posts: 3530
Joined: Tue Mar 01, 2005 6:28 pm
Location: DooBDee.net

Postby pentapenguin on Thu Jun 02, 2005 4:00 pm

Close.
Body part needs to be surrounded by (double) quotes.

Code: Select all
mail ($mail, $subject, "Name: $name\nEmail: $email\nWebsite Name: $websitename\nColour Scheme: $colourscheme\nCategory: $catergory\nDomain: $domain\nLogo: $logo\nNavigation: $navi\nAdditional Info: $add");
User avatar
pentapenguin
Moderator
Moderator
 
Posts: 1466
Joined: Tue Sep 14, 2004 4:15 pm
Location: Georgia, USA

Postby robbie on Sun Jun 05, 2005 8:29 am

add the fourth argument: "FROM: ".$_POST["email"] to make the email sender appear as what they enter in that field, otherwise it will come saying from "Nobody" or something random like "foobar.username@yoursites.gobbleturkey.com" etc., so:

Code: Select all
mail ($mail, $subject, "Name: $name\nEmail: $email\nWebsite Name: $websitename\nColour Scheme: $colourscheme\nCategory: $catergory\nDomain: $domain\nLogo: $logo\nNavigation: $navi\nAdditional Info: $add", "FROM: {$email}");
User avatar
robbie
Coder
Coder
 
Posts: 67
Joined: Fri Mar 12, 2004 4:40 am
Location: New Zealand

RE:mail()

Postby roders22 on Thu Jun 16, 2005 10:38 am

If thats helpful i've done mine like this:

1.$mail_address=$_POST['e_add'];
2.$subject=$_POST['subject'];
3.$content1=$_POST['content1'];
4.$content2=$_POST['content2'];
5.$content3=$_POST['content3'];
6.$from="me@mail.com";

then i've concatenate my mail content like this:

$mailcontent=$content1."\n"
.$content2."\n"
.$content3."\n";

then the mail function:
mail($mail_address, $subject, $mailcontent, $from);

hope it helps.


[/list]
User avatar
roders22
Registered User
Registered User
 
Posts: 141
Joined: Thu Jun 09, 2005 4:33 pm
Location: Mauritius


Return to PHP Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron