Don't Know PHP, Help Me Out Here?

Status
Not open for further replies.

scottspfd82

New member
Dec 29, 2006
1,496
68
0
Okay, I'm building a form for a website. I'm not the best coder in the world, so I borrowed some code from a similar website. Basically, I want the form resultes emailed to me. There's a section of code that says "mailto.php" on the form, which I assume is the code to send the info to an email address or a database. I tried copying the code here, couldn't get it to past for some reason.

After some googling, I found out that "mailto.php" is basically the same as mailto: in html, it's just more secure. So, my question is, where do I find out where they're mailing the results, so I can change my code to send it to me?

If I need to post the code I will.

Thanks,

Scott
 


Not quiet there...

mailto.php is the file/script that the form is going to send its contents to when you hit submit...

The idea is that all of the form data you entered goes to the mailto.php file to be processed and then in your case, mailed to you...

I would get a script together for you but im at work right now...im sure someone else can get something together for you...
 
Here's an example I pulled out of some php. You'd just make sure the html form fields matched up to 'name', 'email', and 'comments'. Then, replace 'you@gmail.com' with the email address you want the message sent to.

Code:
$mailto = 'you@gmail.com' ;

$subject = "http://www.???.com/ Support" ;

$formurl = "http://www.???.com/" ;
$errorurl = "http://www.???.com/" ;
$thankyouurl = "http://www.???.com/" ;

$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
        header( "Location: $formurl" );
        exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
   header( "Location: $errorurl" );
   exit ;
}
if (get_magic_quotes_gpc()) {
        $comments = stripslashes( $comments );
}

$messageproper =

        "This message was sent from:\n" .
        "$http_referrer\n" .
        "------------------------- COMMENTS -------------------------\n\n" .
        $name .
        "\n" .
        $email .
        "\n" .
        $comments .
        "\n" .
        "\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper, "From: \"$name\" <$email>\nReply-To: \"$name\" <$email>\nX-Mailer: chfeedback.php 2.03" );
header( "Location: $thankyouurl" );
exit ;
 
I should have clarified that this is a pretty long lead form. I was hoping someone could tell me where mailto.php goes to get the email address it sends to.

I'll look into those replies though. Thanks.
 
It's kind of hard without seeing mailto.php, but most likely it just fetches the addresses from a MySQL database.
 
Thanks for the responses. Here's basically the form I want to borrow the code and paramaters from.

Compare Home Purchase Mortgage Loan Rates - Home Loans

Is this info being sent to a database? Any easy way to alter the code so it just sends the results to an email account? Just FYI, I'm pretty dumb when it comes to anything beyond HTML, and a little bit of CSS.

Thanks again,

-Scott
 
well really you need to think about this in two pieces. The form is calling a seperate script called mail.php. That script could literally do ANYTHING. Add the data to a db and send and email, record it to a file, enter the data into quickbooks using a com module and the list goes on and on. So basically in reading the html on the page it's passing the data from the form fields to a script called mailto.php. So the script is going to get the data passed to it from the form in a global variable called $_GET, $_POST or $_REQUEST. It's passed in the form of an array so for example an array is a data holder that's a lot like a train. Each train car has a name which is the equivalent in to the id in the form field properties. Then what's in the train car is is the value entered into the textbox, checkbox, etc. So basically the form passes a whole train of cars with the name=>value which you php script can pick up and do whatever you want with.

Mailing things is SUPER simple in php, you can actually do it in one line. So taking what we had before the form has a field with the id email and then someone enters a value of this@email.com. so your super simple mail script would look like.

<?

$email = $_REQUEST['email'];
mail($email,'this is my subject','this is my body of my email';

?>

Want to save the emails to a txt file on the server to build a mailing list? Well that's easy add one more line. Make a writable file to add them to we'll call it emaillist.txt in this case.

<?

$email = $_REQUEST['email'];
mail($email,'this is my subject','this is my body of my email';
file_put_contents('emaillist.txt',$email,FILE_APPEND);


?>

and that's it, pretty simple huh. Now you can send a nice automatic thank you for your inquiry auto responder and build a mailing list at the same time. I have some basic php tutorials on the site in my sig if you're interested in learning more. Good luck!
 
  • Like
Reactions: scottspfd82
P.S. there's no error checking or anything like that in that script which should be included. It's just a short example to help you understand.
 
Status
Not open for further replies.