Jump to content

Help on mailing form data. Please...


jwk811

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!
Link to comment
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?
Link to comment
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]
Link to comment
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!  :)
Link to comment
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!
Link to comment
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]
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.