Jump to content

Archived

This topic is now archived and is closed to further replies.

jwk811

Help on mailing form data. Please...

Recommended Posts

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.
[code]<?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.";
}
?>[/code]
Is that all thats needed to send mail? Please help me, thank you!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
try this:

[code]
<?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>";
}
?>
[/code]

Share this post


Link to post
Share on other sites
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!  :)

Share this post


Link to post
Share on other sites
[quote]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![/quote]

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!

Share this post


Link to post
Share on other sites
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?
[code]<?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);
?>[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.