Jump to content


form problem


5 replies to this topic

#1 Aussiestinger

    Young Padawan

  • Members
  • Pip
  • 270 posts

Posted 15 July 2006 - 05:50 PM

<?PHP
if ($submit) {
//Here we add the send mail script
$from="From:$name<$mail>";
$tomail="a7xrjw@hotmail.com";
if (mail($tomail,$subject,$body,$from)) echo "<h1>Thank you</h1> We have succesfully recieved your information, we will get back to you as soon as possible, always within the next 48 hours. If you do not recieve a reply within 48 hours, please use on of the othr methods of contacting me.
<h1>Other forms of Contact</h1>
<strong>Email:</strong> Webmaster@reclusiveart.com <br />
<strong>Email #2:</strong> a7xrjw@hotmail.com.com <br />
<strong>MSN:</strong> a7xrjw@hotmail.com.com <br />";
}else
//We added action=$PHP_SELF
//$PHPSELF means current page
//action normally contains the page to which the variables are sent
echo "<h1>Email Form</h1>
<form method=POST name=form1 action='$PHP_SELF'>
Name:<br /><input id=name name=name type=text><br />
E-Mail:<br /><input id=email name=mail type=text><br />
Subject:<br /><input id=subject name=subject type=text><br />
Detail:<br /><textarea id=detail name=body></textarea><br />
<input type=submit name=submit value=OK>
</form>
<h1>Other forms of Contact</h1>
<strong>Email:</strong> Webmaster@reclusiveart.com <br />
<strong>Email #2:</strong> a7xrjw@hotmail.com.com <br />
<strong>MSN:</strong> a7xrjw@hotmail.com.com <br />";
?>

That's what i have, the weird thing is it works all the time if in email you don't put @wherever.com (when you fill in the form, not where it sends to) but if you put that it doesn't send (I think it has once not sure). Why? :o

Edited by Aussiestinger, 15 July 2006 - 05:51 PM.


#2 danieldaniel

    Young Padawan

  • Members
  • Pip
  • 75 posts
  • Gender:Male
  • Location:Columbus, Ohio
  • Interests:Skateboarding, Macs, BMX, Cocoa, PHP, CSS etc.

Posted 15 July 2006 - 10:28 PM

If I read that right, then it should be fixed by replacing this:

if (mail($tomail,$subject,$body,$from))

and changing it to:

$from=$_POST['from'];
$header = 'From: '.$from;
if (mail($tomail,$subject,$body, $header))

Edited by danieldaniel, 15 July 2006 - 10:29 PM.


#3 Aussiestinger

    Young Padawan

  • Members
  • Pip
  • 270 posts

Posted 15 July 2006 - 11:05 PM

Well it sends fine.
As long as there is no @domain.com in the Email field in the form.

Wont send
Name: djddjp
Email: pjdjp@pdjkdj.com
Subject: dididh
Detail: dj cij ifjpf j pj


Will send
Name: djddjp
Email: pjdjp
Subject: dididh
Detail: dj cij ifjpf j pj

Edited by Aussiestinger, 15 July 2006 - 11:06 PM.


#4 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 16 July 2006 - 01:58 AM

That is why poorly formatted out-of-date tutorials need to be updated :blush:

<?PHP
if($_POST['submit']){
	if(mail('a7xrjw@hotmail.com', $_POST['subject'], $_POST['body'], 'From: '.$_POST['name'].' <'.$_POST['mail'].'>')){
		echo "<h1>Thank you</h1> We have succesfully recieved your information, we will get back to you as soon as possible, always within the next 48 hours. If you do not recieve a reply within 48 hours, please use on of the othr methods of contacting me.
		<h1>Other forms of Contact</h1>
		<strong>Email:</strong> Webmaster@reclusiveart.com <br />
		<strong>Email #2:</strong> a7xrjw@hotmail.com.com <br />
		<strong>MSN:</strong> a7xrjw@hotmail.com.com <br />";
	}
}else{
	echo '<h1>Email Form</h1>
	<form method="POST" name="form1" action="'.$_SERVER['PHP_SELF'].">
	Name:<br /><input id="name" name="name" type="text"><br />
	E-Mail:<br /><input id="email" name="mail" type="text"><br />
	Subject:<br /><input id="subject" name="subject" type="text"><br />
	Detail:<br /><textarea id="detail" name="body"></textarea><br />
	<input type="submit" name="submit" value="OK">
	</form>
	<h1>Other forms of Contact</h1>
	<strong>Email:</strong> Webmaster@reclusiveart.com <br />
	<strong>Email #2:</strong> a7xrjw@hotmail.com.com <br />
	<strong>MSN:</strong> a7xrjw@hotmail.com.com <br />';
}
?>
I believe the lack of a space between the name and the e-mail in the From header would be the main problem.

If you have any more problems, i would recommend reading what php.net has to say.
http://php.net/manua...nction.mail.php

Edited by rc69, 16 July 2006 - 02:02 AM.


#5 Aussiestinger

    Young Padawan

  • Members
  • Pip
  • 270 posts

Posted 16 July 2006 - 09:40 AM

Thanks, that one actually worked, third try always works eh, thanks heaps.

oh and at first it didn't work, but I added ' before the " in this bit.

action="'.$_SERVER['PHP_SELF']."

Was I right in adding that? like you made a typo, cause it does work, just want to make sure the little bit i have learnt in PHP is right :)

#6 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 16 July 2006 - 10:57 AM

yep you would use the period for and. and you would escape the echo using the same type of quote so .' would've been right :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users