I have a problem with mail form it's .....

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

Post Reply
kujtim
Forum Commoner
Posts: 35
Joined: Sat Oct 25, 2003 4:00 am
Location: kosovo
Contact:

I have a problem with mail form it's .....

Post by kujtim »

this is an standard mail form
but if a would like to send a some thing else for example :first name: <input name="first" type="text" /><br />
what should i do please helpppp..

<html>
<body>
<form method="post" action="sendmail.php">
Email: <input name="email" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>
</body>
</html>
<html>

<head>
<title></title>
</head>

<body>

<?php


$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

mail( "kujtim009@hotmail.com", "Feedback Form Results",
$message, "From: $email" );
header( "Location: http://www.example.com/thankyou.html" );




?>

</body>

</html>
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

mail with attachments and everything

Post by itsmani1 »

Code: Select all

<?php 

// some local variables 
$from_name = "Sender Name"; 
$from_email = "sender@server.ca"; 
$to_name = "Recipient Name"; 
$to_email = "recipient@server.ca"; 
$subject = "Fantastic Subject"; 

// headers need to be in the correct order... 
$headers = "From: $from_name<$from_email>\n"; 
$headers .= "Reply-To: <$from_email>\n"; 
$headers .= "MIME-Version: 1.0\n"; 
// the following must be one line (post width too small) 
$headers .= "Content-Type: multipart/related; 
type="multipart/alternative"; boundary="---- 
=MIME_BOUNDRY_main_message"\n"; 
// 
$headers .= "X-Sender: $from_name<$from_email>\n"; 
$headers .= "X-Mailer: PHP4\n"; //mailer 
$headers .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal 
$headers .= "Return-Path: <$from_email>\n"; 
$headers .= "This is a multi-part message in MIME format.\n"; 
$headers .= "------=MIME_BOUNDRY_main_message \n"; 
$headers .= "Content-Type: multipart/alternative; boundary="----=MIME_BOUNDRY_message_parts"\n"; 

//plaintext section begins 
$message = "------=MIME_BOUNDRY_message_parts\n"; 
$message .= "Content-Type: text/plain; charset="iso-8859-1"\n"; 
$message .= "Content-Transfer-Encoding: quoted-printable\n"; 
$message .= "\n"; 

// your text goes here 
$message .= "blah blah -- plaintext version of the message\n"; 
$message .= "\n"; 

// html section begins 
$message .= "------=MIME_BOUNDRY_message_parts\n"; 
$message .= "Content-Type: text/html;\n    charset="iso-8859-1"\n"; 
$message .= "Content-Transfer-Encoding: quoted-printable\n"; 
$message .= "\n"; 

// your html goes here -- It didn't appear properly without 
// the weird markup that outlook added after sending 
$message .= "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\n"; 
$message .= "<HTML><BODY>\n"; 
$message .= "blah blah -- html version of the message\n"; 

// look ma, I'm referencing an img attachment (see below) 
// watch out for weird markup!!! 
$message .= "<IMG src=3D"cid:some_picture">\n"; 
$message .= "</BODY></HTML>\n"; 
$message .= "\n"; 

// this ends the message part 
$message .= "------=MIME_BOUNDRY_message_parts--\n"; 
$message .= "\n"; 

// now we add attachments (images, etc) 
$message .= "------=MIME_BOUNDRY_main_message\n"; 
$message .= "Content-Type: image/gif; \n name="some_picture.gif"\n"; 
$message .= "Content-Transfer-Encoding: base64\n"; 
$message .= "Content-ID: <some_picture>\n"; 
$message .= "\n"; 
// (truncated for space) 
$message .= "R0lGODlheAAZAKIHAMTExCQkJJOTk\n"; 
$message .= "eLo7wzDKSatVQ5R3u7dDUUjcZ34D\n"; 
$message .= "\n"; 
// etc...etc...etc... 

//message ends 
$message .= "------=MIME_BOUNDRY_main_message--\n"; 

// send the message  
mail("$to_name<$to_email>", $subject, $message, $headers); 



?>
Regardsssss
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

That's a lot of code itsmani1 and pretty overcomplicated for what kujtim is trying to do ;).

kujtim -
Try this

Code: Select all

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Contact Form&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;form method="post" action="sendmail.php"&gt;
	&lt;p&gt;
		First Name: &lt;input name="first" type="text" /&gt;&lt;br /&gt; 
		Last Name: &lt;input name="last" type="text" /&gt;&lt;br /&gt; 
		Email: &lt;input name="email" type="text" /&gt;&lt;br /&gt;
		Message:&lt;br /&gt;
		&lt;textarea name="message" rows="15" cols="40"&gt;&lt;/textarea&gt;&lt;br /&gt;
		
		&lt;input type="hidden" name="action" value="post" /&gt;
		&lt;input type="submit" /&gt;
	&lt;/p&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Now in sendmail.php

Code: Select all

<html>
<head>
<title>Contact form sent</title>
</head>

<body>

<?php

// first check if the form has been submitted
// we use $_POST because the values are coming via the POST method
if (isset($_POST['action']) && $_POST['action'] == 'post') {
	$first_name = $_POST['first'];
	$last_name  = $_POST['last'];
	$email      = $_POST['email'];
	$message    = $_POST['message'];

	$content =<<<END
A message has been received via the website:-
	
From: $first_name $last_name

Message:
$message
END;
	
	$to_email = 'kujtim009@hotmail.com';
	$subject  = 'Feedback Form Results';
	$headers  = 'From: '.$email;

	// we use @ to stop error messages showing to the user if the e-mail
	// can't be sent because there's a problem on the server.
	@mail($to_email, $subject, $content, $headers);

	header('Location: thankyou.html');
}

?>

</body>
</html>
Mac
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

@itsmani1, that'll just confuse him. I've seen most of your posts, you might want to start advising people a little more rather than just post a plain code? He can go to EvilWalrus.com if he wanted a script.

@kujtim

Here's how you do it. Say you have a form:

Code: Select all

&lt;form name="form" method="post" action="sendmail.php"&gt;
Name: &lt;input type="text" name="sender_name" /&gt;&lt;br /&gt;
From: &lt;input type="text" name="email" /&gt;&lt;br /&gt;
&lt;textarea name="comment" rows="10" cols="50"&gt;&lt;/textarea&gt;&lt;br /&gt;
&lt;input type="submit" name="submit" value="Submit" /&gt;
&lt;/form&gt;
That shouldn't be too hard for you. If your wondering the <br /> and <input />, these are XHTML syntax. You might want to start using XHTML since HTML is going to be extinct soon - well, not so soon I guess. Anyhow, here's sendmail.php.

Code: Select all

<?php

// declare variables - makes life easier
$sender_name = $_POST['sender_name']; // use $_POST, since you know it's coming from a form with a POST method
$email = $_POST['email'];
$comment = $_POST['comment'];
$submit = $_POST['submit'];

// check if form is submitted

if(isSet($submit) && !empty($submit) {
// send mail

// declare variable "message" to send
$message = <<< MSG
Name: $sender_name\n
Message:\n
$comment
MSG;

// send mail
$send = mail("kujtim009@hotmail.com", "Feedback Form Results", $message, "From: $email");

// check if e-mail was sent
if(isSet($send)) {
header("Location: thankyou.html");
} else {
echo "Sorry, PHP could not send the e-mail";
}

} else {
echo "Error! Could not send mail!";
}

?>
Hope that helps!

-Nay
Last edited by Nay on Wed Oct 29, 2003 5:43 am, edited 1 time in total.
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

*snap*

Mac's always faster :(

............or I just type too slow :(

-Nay
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

mwha, ha, ha

Mac
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Sing along in the PowerPuff Girls tune.
Huh

Jason, the most experianced useR.......
Wally, he's always flapping aRounD.........
MacKK, and the fastest typer........
PHPDN saves the day

fighting ASP
Trying to save the world
And then we're just in time
The PHPDN teammmmmmm
fighting M$
Trying to save the world
And then we're just in time
the PHPDN teammmmmmm

PHPDN!!!
Okay, I couldn't include all the dudes but yerr :lol:. Oh sorry for getting off topic :P but I just had to :D.

-Nay
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

Nay wrote:Sing along in the PowerPuff Girls tune.
Huh

Jason, the most experianced useR.......
Wally, he's always flapping aRounD.........
MacKK, and the fastest typer........
PHPDN saves the day

fighting ASP
Trying to save the world
And then we're just in time
The PHPDN teammmmmmm
fighting M$
Trying to save the world
And then we're just in time
the PHPDN teammmmmmm

PHPDN!!!
Okay, I couldn't include all the dudes but yerr :lol:. Oh sorry for getting off topic :P but I just had to :D.

-Nay
still, i think that gets the most important ones.... jason, who i get the impression owns the site, and mac, who seems to spend every spare moment making sure this is an absolutely awesome place and extremely useful.

wally seems to help a lot, specially since we point those looking for scripts to his site.. hmm... maybe macgruff since he's rather good with giving a post that highlights the errors in constructive ways so that everyone learns from the mistake and knows how to fix it ... i mean instead of evil walrus since mcgruff seems to be here more....
Post Reply