Jump to content


Photo

Help on mailing form data. Please...


  • Please log in to reply
11 replies to this topic

#1 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 29 September 2006 - 01:11 AM

I've been searching on here to find out how I could send mail in a form using php. It looks like all that is needed is the $mail variable, but I thought it was all more complicated than that. Here's a script that a form a found on here goes to.
<?php
if(isset($_POST[email])){
$name=$_POST['name'];
$mail_to = "name@domain.com";
$mail_subject="Online Inquery Form from Peakmore.com";
$mail_body = "Message Sent From: ".$name."\r\n<br />";
$mail_body .= wordwrap({$_POST['emailmessage']},72,"<br />\r\n");
    if (mail($mail_to, $mail_subject, $mail_body, "From:$emailaddress")){
        echo "Thank you.";
    }
    else
    {
        echo "Failed to send. Please try again.";
    }
}
else
{
echo "You have not filled in your email address.";
}
?>
Is that all thats needed to send mail? Please help me, thank you!

#2 Demonic

Demonic
  • Members
  • PipPipPip
  • Advanced Member
  • 562 posts

Posted 29 September 2006 - 01:15 AM

yeah for a basic email buut wheres the forum?

#3 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 29 September 2006 - 01:23 AM

Really? Wow. I was trying to set up some kind of email thing which was really hard, didnt know that I could just do that.. whats the difference when you say basic email? What are the disadvantages.. is there a delay before I'd recieve an email like all form processors have? I'll show you a form and I hope you can say if the script it's sent to will work or not. Could you actually show me a script I could use do send form mail? All I would need to do is replace all the input data into variables and add the mail subject and body variables, and in the body post the form data variables, correct? Which piece actually sends the mail?

#4 Demonic

Demonic
  • Members
  • PipPipPip
  • Advanced Member
  • 562 posts

Posted 29 September 2006 - 01:28 AM

try this:

<?php
//Copy Demonic.
$from = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['question']."\n\n\n\n\n-------------------\n User's IP is ".$_SERVER['REMOTE_ADDR']."\n-----------------\n";
if(isset($_POST['sendquestion'])){
$user = explode("@", $from);
mail("YOUREMAIL@SOMESITE.COM", $subject, $message, "From: " ."EMAIL NAME THING HERE - ". $user[0] . "<" . $from . ">\n");
echo "YOUR MESSAGE";
}else{
echo"<center>
<form method='post'>
<table>
<tr>
<td><input type='text' name='email' value='Your Email'></td>
</tr>
<tr>
<td><input type='text' name='subject' value='Subject'></td>
</tr>
<tr>
<td><textarea name='question'></textarea></td>
</tr>
</table>
<br>
<input type='submit' name='sendquestion' value='Send Your Support Ticket'><br>
</form>
</center>";
} 
?>


#5 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 29 September 2006 - 01:34 AM

Could I could just add that all onto the form page without having to send the data to a script? Would I still be able to send the data to another page after that? And I not very good with this but which places should I replace and with what? And thank you very much for helping me, I really apreciate it!  :)

#6 Demonic

Demonic
  • Members
  • PipPipPip
  • Advanced Member
  • 562 posts

Posted 29 September 2006 - 01:39 AM

Can you tell me exactly what you mean please.  ;)

#7 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 29 September 2006 - 01:44 AM

Could I could just add that all onto the form page without having to send the data to a script? Would I still be able to send the data to another page after that? And I not very good with this but which places should I replace and with what? And thank you very much for helping me, I really apreciate it!


In the script you wrote you have the mailing thing on the same page as the form. I thought you were supposed to direct the form to that script in a different file. And what should I replace in the script you wrote with my own things I'm going to be needing. Sorry for being unclear...  ;D Thanks!

#8 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 29 September 2006 - 01:46 AM

And i just found this code to test out an email. How would I do this like it's just a code how will I make it work?
<?php$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";mail($to,$subject,$txt,$headers);
?>


#9 Demonic

Demonic
  • Members
  • PipPipPip
  • Advanced Member
  • 562 posts

Posted 29 September 2006 - 01:50 AM

from that script you found edit the $to varible to your email then upload script and go to link and then check your email.


And know you dont have to redirect the script to the PHP files to work.

Just edit (in the script i posted):
mail("YOUREMAIL@SOMESITE.COM",

your email^

echo "YOUR MESSAGE";
^your message(this will show once you click submit to send the email)

say i put

echo "Your email was sent.";

just letting you know nothen went wrong. :).

upload the script and try it out and view your email.


#10 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 29 September 2006 - 01:57 AM

okay i just unloaded that php file into my ftp server. i went to the web address and this came up
Parse error: parse error, unexpected T_VARIABLE in /home/content/j/w/k/jwk811/html/testemail.php on line 1


#11 Demonic

Demonic
  • Members
  • PipPipPip
  • Advanced Member
  • 562 posts

Posted 29 September 2006 - 02:12 AM

please check the other topic you created. (why didnt you use the one I had?)

#12 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 29 September 2006 - 02:16 AM

ok because i saw that you left or your name wasnt at top so i thought you were gone and people dont usually look at the threads that have a lot of posts as in they're done and a new thread usually someone you step up to help first lol




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users